Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support iso-year-week-day in calendar_leap_year() #333

Merged
merged 3 commits into from
Apr 26, 2023

Conversation

DavisVaughan
Copy link
Member

@DavisVaughan DavisVaughan commented Apr 21, 2023

library(clock)

x <- iso_year_week_day(2020:2030)
x
#> <iso_year_week_day<year>[11]>
#>  [1] "2020" "2021" "2022" "2023" "2024" "2025" "2026" "2027" "2028" "2029"
#> [11] "2030"

calendar_leap_year(x)
#>  [1]  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE

x[calendar_leap_year(x)]
#> <iso_year_week_day<year>[2]>
#> [1] "2020" "2026"


# Test that it works right.
# Exactly 71 leap weeks for any 400 year cycle.
start <- 1900

while (start < 2000) {
  end <- start + 400 - 1
  x <- seq(start, end)
  x <- iso_year_week_day(x)
  
  if (sum(calendar_leap_year(x)) != 71) {
    stop("something is horribly wrong!")
  }
  
  start <- start + 1
}

Created on 2023-04-21 with reprex v2.0.2.9000

@DavisVaughan DavisVaughan merged commit a952b40 into main Apr 26, 2023
@DavisVaughan DavisVaughan deleted the feature/iso-leap-year branch April 26, 2023 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant