Reputation: 4145
I am parsing dates with lubridate::parse_date_time
and some dates just don't work. For example, why does 2004-04-04 02:00
return NA
but 2004-04-04 01:00
and 2004-04-04 03:00
work?
library("lubridate")
"2004-04-04 01:00" %>% parse_date_time(c("Ymd HM"), tz = "America/New_York")
"2004-04-04 02:00" %>% parse_date_time(c("Ymd HM"), tz = "America/New_York")
"2004-04-04 03:00" %>% parse_date_time(c("Ymd HM"), tz = "America/New_York")
Here are two other examples that return NA
:
"20110313 0240" %>% parse_date_time(c("Ymd HM"), tz = "America/New_York")
"20130310 0255" %>% parse_date_time(c("Ymd HM"), tz = "America/New_York")
I am using lubridate version 1.6.0.
Upvotes: 1
Views: 163
Reputation: 16036
There was no 2004-04-04 02:00
in America/New_York
. After 2004-04-04 01:59:59 EST
, the clock ticked forward to 2004-04-04 03:00:00 EDT
, starting daylight saving time.
Your timestamps are likely stored in EST5
rather than America/New_York
.
> "2004-04-04 01:00" %>% parse_date_time(c("Ymd HM"), tz = "EST5") %>% with_tz("America/New_York")
[1] "2004-04-04 01:00:00 EST"
> "2004-04-04 02:00" %>% parse_date_time(c("Ymd HM"), tz = "EST5") %>% with_tz("America/New_York")
[1] "2004-04-04 03:00:00 EDT"
Upvotes: 2