Skip to content

Commit fa038fa

Browse files
committed
allow dash-separate dates to be parsed
1 parent 2fce66d commit fa038fa

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

R/model.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ parse_data_frame <- function(epidata_call, df, disable_date_parsing = FALSE) {
174174

175175
#' @keywords internal
176176
parse_api_date <- function(value) {
177-
as.Date(as.character(value), format = "%Y%m%d")
177+
as.Date(as.character(value), tryFormats = c("%Y%m%d", "%Y-%m-%d"))
178178
}
179179

180180
#' parse_api_week converts an integer to a date

tests/testthat/test-model.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,13 @@ test_that("parse_data_frame warns when df contains fields not listed in meta", {
9898
mock_df$rate_age_0 <- NULL
9999
expect_no_warning(parse_data_frame(epidata_call, mock_df))
100100
})
101+
102+
test_that("parse_api_date accepts str and int input", {
103+
expect_identical(parse_api_date("20200101"), as.Date("2020-01-01"))
104+
expect_identical(parse_api_date(20200101), as.Date("2020-01-01"))
105+
})
106+
107+
test_that("parse_api_date accepts YYYYMMDD and YYYY-MM-DD", {
108+
expect_identical(parse_api_date(20200101), as.Date("2020-01-01"))
109+
expect_identical(parse_api_date("2020-01-01"), as.Date("2020-01-01"))
110+
})

0 commit comments

Comments
 (0)