Skip to content

Commit

Permalink
[Fix #1002] Fix parsing only with j format work on numeric inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
vspinu committed Oct 9, 2021
1 parent 08e0329 commit 9cece56
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Version 1.8.0.9000

* [#1001](https://github.com/tidyverse/lubridate/issues/1001) Add `%within` method with signature (Interval, list), which was documented but not implemented.

### BUG FIXES

* [#1002](https://github.com/tidyverse/lubridate/issues/1002) Parsing only with format `j` now works on numeric inputs.

Version 1.8.0
=============
Expand Down
7 changes: 5 additions & 2 deletions R/parse.r
Original file line number Diff line number Diff line change
Expand Up @@ -904,14 +904,17 @@ fast_strptime <- function(x, format, tz = "UTC", lt = TRUE, cutoff_2000 = 68L) {
}

.num_to_date <- function(x) {
if (is.numeric(x)) {
# #1002 lower numbers are normally something else than full dates
if (is.numeric(x) && x > 1900) {
out <- rep.int(as.character(NA), length(x))
nnas <- !is.na(x)
x <- format(x[nnas], scientific = FALSE, trim = TRUE)
x <- paste(ifelse(nchar(x) %% 2 == 1, "0", ""), x, sep = "")
out[nnas] <- x
out
}else as.character(x)
} else {
as.character(x)
}
}

.parse_iso_dt <- function(x, tz) {
Expand Down
6 changes: 5 additions & 1 deletion tests/testthat/test-parsers.R
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,11 @@ test_that("parsing months with dots works in French linux locale", {
c("févr", "mars", "avril"))
})


test_that("parsing with j format works correctly", {
## https://github.com/tidyverse/lubridate/issues/1002
expect_equal(yday(parse_date_time(100, "j")), 100)
expect_equal(yday(parse_date_time(c(1, 150, 330), "j")), c(1, 150, 330))
})

## library(microbenchmark)
## library(lubridate)
Expand Down

0 comments on commit 9cece56

Please sign in to comment.