[Rd] strptime problem for 2004-10-03 02:00:00

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Oct 25 22:33:54 CEST 2005


It's a bug, a rather rare one.  2004-10-03 02:00:00 does not exist in your 
time zone, and in trying to find out if the time is on DST or not it has 
failed to find out.  It needs to be told that GMT is never on DST so not 
to bother.

On Linux, running R with TZ="GMT" set should fix this.  Windows is harder 
to control since it does not distinguish the UK timezone from GMT.

There is a bugfix now in R-devel.  It may migrate to R-patched in due 
course.

On Tue, 25 Oct 2005, Michael Sumner wrote:

> 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
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list