Search code examples
rlubridate

Why does lubridate::ymd_hms not work for a very specific date-time?


I have the date-time 2019-03-10 02:43:00 in POSIXct format. Note the following behavior:

lubridate::ymd_hms("2019-03-10 02:43:00",  tz = "America/Los_Angeles")
[1] NA
Warning message:
 1 failed to parse.

lubridate::ymd_hms("2019-03-10 01:59:00",  tz = "America/Los_Angeles")
[1] "2019-03-10 01:59:00 PST"

lubridate::ymd_hms("2019-03-10 03:00:00",  tz = "America/Los_Angeles")
[1] "2019-03-10 03:00:00 PDT"

Any time value between 02:00 - 02:59 for this date gives ```NA``.


Solution

  • The answer is that in the US/Pacific time zone on 2019-03-10 changed to daylight savings at 02:00, making any time on this day between 02:00 - 02:59 ambiguous.

    Edit: As noted by Rui in the comments, the 2nd Sunday in March is the official switch to daylight savings in the US.

    I am posting in the hope that others find this useful for troubleshooting.