calendar_leap_year {clock}R Documentation

Is the calendar year a leap year?

Description

calendar_leap_year() detects if the calendar year is a leap year - i.e. does it contain one or more extra components than other years?

A particular year is a leap year if:

Usage

calendar_leap_year(x)

Arguments

x

⁠[calendar]⁠

A calendar type to detect leap years in.

Value

A logical vector the same size as x. Returns TRUE if in a leap year, FALSE if not in a leap year, and NA if x is NA.

Examples

x <- year_month_day(c(2019:2024, NA))
calendar_leap_year(x)

# For year-quarter-day, the leap year typically aligns with the Gregorian
# leap year, unless the `start` is February, in which case the leap year is
# always 1 year after the Gregorian leap year
x <- year_quarter_day(2020:2021, start = clock_months$january)
calendar_leap_year(x)

x <- year_quarter_day(2020:2021, start = clock_months$february)
calendar_leap_year(x)

# With a January start, 2020 has the extra day
get_day(year_quarter_day(2020, 1:4, "last", start = clock_months$january))
get_day(year_quarter_day(2021, 1:4, "last", start = clock_months$january))
get_day(year_quarter_day(2022, 1:4, "last", start = clock_months$january))

# With a February start, 2021 has the extra day
get_day(year_quarter_day(2020, 1:4, "last", start = clock_months$february))
get_day(year_quarter_day(2021, 1:4, "last", start = clock_months$february))
get_day(year_quarter_day(2022, 1:4, "last", start = clock_months$february))

[Package clock version 0.7.0 Index]