diff --git a/NEWS.md b/NEWS.md index 653c393b..7a357eed 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,6 +15,7 @@ Version 1.7.4.9000 * [#778](https://github.com/tidyverse/lubridate/issues/778) `duration()` works with repeated units * [#682](https://github.com/tidyverse/lubridate/issues/682) Fix quarter extraction with small `fiscal_start`s. +* [#703](https://github.com/tidyverse/lubridate/issues/703) `leap_year()` works with objects supported by `year()`. Version 1.7.4 diff --git a/R/leap-years.r b/R/leap-years.r index 44763edf..8d22526a 100644 --- a/R/leap-years.r +++ b/R/leap-years.r @@ -16,12 +16,10 @@ #' leap_year(1900) # FALSE #' leap_year(2000) # TRUE leap_year <- function(date) { - recognized <- recognize(date) - if (recognized) - year <- year(date) - else if (all(is.numeric(date))) + if (is.numeric(date)) { year <- date - else - stop("unrecognized date format") + } else { + year <- year(date) + } (year %% 4 == 0) & ((year %% 100 != 0) | (year %% 400 == 0)) } diff --git a/R/util.r b/R/util.r index eda58349..3968124c 100644 --- a/R/util.r +++ b/R/util.r @@ -15,14 +15,6 @@ match_lengths <- function(x, y) { list(x, y) } -recognize <- function(x) { - recognized <- c("POSIXt", "POSIXlt", "POSIXct", "yearmon", "yearqtr", "Date") - - if (all(class(x) %in% recognized)) - return(TRUE) - return(FALSE) -} - standardise_date_names <- function(x) { dates <- c("second", "minute", "hour", "mday", "wday", "yday", "day", "week", "month", "year", "tz") y <- gsub("(.)s$", "\\1", x)