Skip to content

Commit

Permalink
fix #300 fix cpc_prcp, us=TRUE should allow back to 1948
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Feb 27, 2019
1 parent 2483552 commit 1094a7e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion R/cpc.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@
cpc_prcp <- function(date, us = FALSE, drop_undefined = FALSE, ...) {
assert(date, c("character", "Date"))
assert(us, 'logical')
stopifnot(length(us) == 1)
dates <- str_extract_all_(date, "[0-9]+")[[1]]
assert_range(dates[1], 1979:format(Sys.Date(), "%Y"))
if (us) {
assert_range(dates[1], 1948:format(Sys.Date(), "%Y"))
} else {
assert_range(dates[1], 1979:format(Sys.Date(), "%Y"))
}
assert_range(as.numeric(dates[2]), 1:12)
assert_range(as.numeric(dates[3]), 1:31)

Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-cpc_prcp.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,12 @@ test_that("cpc_prcp fails well", {
"date must be of class character, Date")
expect_error(cpc_prcp("2017-01-15", us = 5),
"us must be of class logical")

# acceptable years
## non us
expect_error(cpc_prcp("1945-01-01"), "must be between")
expect_error(cpc_prcp(Sys.Date() + 365), "must be between")
## us
expect_error(cpc_prcp("1947-12-31", us = TRUE), "must be between")
expect_error(cpc_prcp(Sys.Date() + 365, us = TRUE), "must be between")
})

0 comments on commit 1094a7e

Please sign in to comment.