is_leap_year(2020)
(days_this_year <- 365 + is_leap_year(Sys.Date()))
# from dates:
is_leap_year(Sys.Date())
is_leap_year(as.Date("2022-02-28"))
# from times:
is_leap_year(Sys.time())
is_leap_year(as.POSIXct("2022-10-11 10:11:12"))
is_leap_year(as.POSIXlt("2022-10-11 10:11:12"))
# from non-integers:
is_leap_year(2019.5)
# For vectors:
is_leap_year(2020:2028)
# with dt as strings:
is_leap_year(c("2020", "2021"))
is_leap_year(c("2020-02-29 01:02:03", "2021-02-28 01:02"))
# Note: Invalid date string yields error:
# is_leap_year("2021-02-29")
Run the code above in your browser using DataLab