converting "1984-03-25 02:00:00" to POSIX gives NA

153 views Asked by At

While converting a vector of date-time to POSIXlt, just one particular time "25-Mar-1984-02:00" "is converted to POSIXlt but returns NA! So, this row was getting omitted in my analysis/plots.

is.na(as.POSIXlt("25-Mar-1984-02:00",format = "%d-%b-%Y-%H:%M"))
is.na(as.POSIXlt("25-Mar-1984-03:00",format = "%d-%b-%Y-%H:%M"))
is.na(as.POSIXlt("25-Mar-1984-01:00",format = "%d-%b-%Y-%H:%M"))
is.na(as.POSIXlt("24-Mar-1984-02:00",format = "%d-%b-%Y-%H:%M"))
is.na(as.POSIXlt("26-Mar-1984-02:00",format = "%d-%b-%Y-%H:%M"))

returns TRUE, FALSE, FALSE, FALSE, FALSE.

but

class(as.POSIXlt("25-Mar-1984-02:00",format = "%d-%b-%Y-%H:%M"))

returns [1] "POSIXlt" "POSIXt"

Isn't that strange? How can I get it to be "not NA"?

1

There are 1 answers

0
Joshua Ulrich On BEST ANSWER

While you don't say what your timezone is, this looks like Daylight Saving Time (DST) issue. In timezones that use DST, there will be a day where the hour "jumps" from 1:59:59.999 to 3:00:00.000. This means that any times in the 2AM hour do not exist on this day.

My guess is that 1984-03-25 02:00:00 is when DST occurs in your local timezone.