Skip to content

Commit

Permalink
simplify leap_year() to use year() (#820)
Browse files Browse the repository at this point in the history
Fixes #703
  • Loading branch information
earowang authored and hadley committed Nov 20, 2019
1 parent 3a96b19 commit 6b3431a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions R/leap-years.r
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
8 changes: 0 additions & 8 deletions R/util.r
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6b3431a

Please sign in to comment.