[Rd] strptime problem for 2004-10-03 02:00:00
Michael Sumner
mdsumner at utas.edu.au
Tue Oct 25 07:42:37 CEST 2005
Hello, I at first thought this was a system or locale issue, but since
it occurs on
both Windows and Linux and only for 2004 (AFAIK) I report it.
I have a problem with as.POSIXct for the hour between
"2004-10-03 02:00:00 GMT" and "2004-10-03 02:59:59 GMT".
In short, the 2 AM (GMT) hour in 2004 (but not in other years) is
interpreted as 1 AM by strptime:
(I use ISOdatetime as a convenience).
## Windows XP
ISOdatetime(2004, 10, 3, 2, 0, 0, tz = "GMT")
##[1] "2004-10-03 01:00:00 GMT"
ISOdatetime(2004, 10, 3, 1, 0, 0, tz = "GMT")
##[1] "2004-10-03 01:00:00 GMT"
ISOdatetime(2005, 10, 3, 2, 0, 0, tz = "GMT")
##[1] "2005-10-03 02:00:00 GMT"
ISOdatetime(2005, 10, 3, 1, 0, 0, tz = "GMT")
## [1] "2005-10-03 01:00:00 GMT"
I've not explored it for other years, but it is not a problem for the
same time in previous and next years.
I only found it as I have a continuous sequence of date-times that cover
that time period, the problem
is not created by traversing that time with seq.POSIXt.
I usually use Windows XP, below I also give results on Linux (release
"2.4.21-37.ELsmp"). On that
machine the times are incorrect in the other direction (in 2004, 2 AM is
interpreted as 3 AM).
My (Windows) system is set to automatically adjust for daylight summer
time, and if I uncheck this and restart R
the problem is "fixed". I don't know how I would do that on Linux, but
it's a server anyway so I couldn't.
## R 2.2.0
## Windows XP, SP2
## System time is set to (GMT+10:00) Hobart - Tasmanian Summer Time (1
hour forward of GMT+10)
Sys.getlocale()
## [1]
"LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_MONETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.1252"
#### Try for 2004
(t1 <- ISOdatetime(2004, 10, 3, 1, 0, 0, tz = "GMT"))
##[1] "2004-10-03 01:00:00 GMT"
(t2 <- ISOdatetime(2004, 10, 3, 2, 0, 0, tz = "GMT"))
##[1] "2004-10-03 01:00:00 GMT"
## no difference - why?
t2 - t1
## Time difference of 0 secs
## Try for 2005
(t1 <- ISOdatetime(2005, 10, 3, 1, 0, 0, tz = "GMT"))
##[1] "2005-10-03 01:00:00 GMT"
(t2 <- ISOdatetime(2005, 10, 3, 2, 0, 0, tz = "GMT") )
##[1] "2005-10-03 02:00:00 GMT"
## 1 hour difference - as expected
t2 - t1
## Time difference of 1 hours
####
#### LINUX
####
## R 2.2.0
## Linux (release "2.4.21-37.ELsmp"
## System time is set to (EST) - summer time (I don't know how to find
more about this)
Sys.getlocale()
## [1]
"LC_CTYPE=en_AU.UTF-8;LC_NUMERIC=C;LC_TIME=en_AU.UTF-8;LC_COLLATE=en_AU.UTF-8;LC_MONETARY=en_AU.UTF-8;LC_MESSAGES=en_AU.UTF-8;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C"
#### Try for 2004
(t1 <- ISOdatetime(2004, 10, 3, 1, 0, 0, tz = "GMT"))
## [1] "2004-10-03 01:00:00 GMT"
(t2 <- ISOdatetime(2004, 10, 3, 2, 0, 0, tz = "GMT"))
##[1] "2004-10-03 03:00:00 GMT"
## difference of 2 hours - why?
t2 - t1
## Time difference of 2 hours
## Try for 2005
(t1 <- ISOdatetime(2005, 10, 3, 1, 0, 0, tz = "GMT"))
##[1] "2005-10-03 01:00:00 GMT"
(t2 <- ISOdatetime(2005, 10, 3, 2, 0, 0, tz = "GMT") )
##[1] "2005-10-03 02:00:00 GMT"
## one hour difference as expected
t2 - t1
## Time difference of 1 hours
More information about the R-devel
mailing list