Question

I experience very strange behaviour of strptime parsing.

This is my R session on windows machine

> R.Version()$version.string
[1] "R version 2.15.2 (2012-10-26)"
> a <- ( strptime(  "29-MAR-13 02.26.53.000000000 AM" , "%d-%B-%y %I.%M.%OS %p" ) )
> str(a)
 POSIXlt[1:1], format: "2013-03-29 02:26:53"
> # convert to double: doesn't work
> as.double(a)
[1] NA
> b <- ( strptime(  "29-MAR-13 04.26.53.000000000 AM" , "%d-%B-%y %I.%M.%OS %p" ) )
> #same as `a`, but another hour
> str(b)
 POSIXlt[1:1], format: "2013-03-29 04:26:53"
> #convert to double: works
> as.double(b)
[1] 1364520413
>  #WTF ???

I have tested the same code on another machine (linux) with different minor version of R. The code worked as expected in both cases:

> R.Version()$version.string
[1] "R version 2.15.1 (2012-06-22)"
> a <- ( strptime(  "29-MAR-13 02.26.53.000000000 AM" , "%d-%B-%y %I.%M.%OS %p" ) )
> str(a)
 POSIXlt[1:1], format: "2013-03-29 02:26:53"
> # convert to double: WORKS!
>  as.double(a)
[1] 1364513213
> b <- ( strptime(  "29-MAR-13 04.26.53.000000000 AM" , "%d-%B-%y %I.%M.%OS %p" ) )
> #same as `a`, but another hour
> str(b)
 POSIXlt[1:1], format: "2013-03-29 04:26:53"
>  #convert to double: works
> as.double(b)
[1] 1364520413
>

Can someone tell me what's the problem? Did I find a bug in R?

Was it helpful?

Solution

Are you in Israel? Googling 'daylight savings time "march 29"' shows that in 2013 DST started on March 29 in Israel, e.g. http://www.timeanddate.com/worldclock/clockchange.html?n=110 ... differences in locale/time zone settings between the two computers you tested could certainly explain this, if one were set to an Israeli time zone and the other weren't. You can check this by using tz="GMT" ...

PS: I looked at your profile and see that you are indeed in Israel. I didn't look before I initially posted the answer!

PPS: A very large fraction of queries about date-time conversion turn out to be about timezone, and specifically daylight-savings-time, issues, which is what led me to the answer in the first place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top