Skip to content

Commit

Permalink
[Fix #448] Correctly handle missing months and days in C parser
Browse files Browse the repository at this point in the history
  • Loading branch information
vspinu committed Aug 3, 2016
1 parent 9839599 commit c601db8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/tparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ SEXP parse_dt(SEXP str, SEXP ord, SEXP formats, SEXP lt) {
}
}

if (succeed ) {
// allow missing months and days
if (m == 0) m = 1;
if (d == 0) d = 1;

if (succeed) {
if(out_lt){

INTEGER(oYEAR)[i] = y - 1900;
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-parsers.R
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,13 @@ test_that("truncation on non-dates results in NAs indeed", {
}))
})

test_that("missing months and days are allowed", {
expect_equal(parse_date_time2("2016", orders = "Y"), ymd("2016-01-01", tz = "UTC"))
expect_equal(parse_date_time2("2016-02", orders = "Ym"), ymd("2016-02-01", tz = "UTC"))
expect_equal(parse_date_time("2016", orders = "Y"), ymd("2016-01-01", tz = "UTC"))
expect_equal(parse_date_time("2016-02", orders = "Ym"), ymd("2016-02-01", tz = "UTC"))
})

test_that("fractional formats are correctly parsed", {
expect_that({
x <- c("2011-12-31 12:59:59.23", "2010-01-01 12:11:10")
Expand Down

0 comments on commit c601db8

Please sign in to comment.