Re: [Rd] daylight saving / time zone issues with as.POSIXlt/as.POSIXct (PR#10392)

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Thu, 01 Nov 2007 18:23:31 +0100

tplate_at_acm.org wrote:
> Running under Windows XP 64 bit, as.POSIXlt()/as.POSIXct() seem
> to think that US time zones (EST5EDT, MST7MDT) switched from daylight
> savings back to standard time on Oct 28, 2007, whereas the switch
> is actually on Sun Nov 04, 2007.
>
>
Not Our Problem. (This sort of thing never is. We are wholly dependent on the OS for this information). Check out

http://support.microsoft.com/kb/933360

> Examples:
>
> > Sys.timezone()
> [1] "Mountain Daylight Time"
> > as.POSIXct("2007-10-30 12:38:47")
> [1] "2007-10-30 12:38:47 Mountain Daylight Time"
> > # *** Should report 2007-10-30 14:38:47 EDT:
> > as.POSIXlt(as.POSIXct("2007-10-30 12:38:47"), "EST5EDT")
> [1] "2007-10-30 13:38:47 EST"
> > Sys.time()
> [1] "2007-11-01 09:22:28 Mountain Daylight Time"
>
> > # Bad behavior is manifested in different ways with TZ="MST7MDT"
> > Sys.setenv(TZ="MST7MDT")
> > # *** Should report "12:38:47 MDT"
> > as.POSIXct("2007-10-30 12:38:47")
> [1] "2007-10-30 12:38:47 MST"
> > as.POSIXlt(as.POSIXct("2007-10-30 12:38:47"), "EST5EDT")
> [1] "2007-10-30 14:38:47 EST"
> > # *** Should report "2007-11-01 09:23:09 MDT"
> > Sys.time()
> [1] "2007-11-01 08:23:09 MST"
> >
> > sessionInfo()
> R version 2.6.0 Patched (2007-10-11 r43143)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
> >
>
>
> Furthermore, with the timezone "Mountain Daylight Time"
> (which is the default I get when I start R), the switch
> appears to be on Nov 5 in 2006, whereas it actually was
> on Oct 29 in 2006.
>
> > # New R session
> > Sys.timezone()
> [1] "Mountain Daylight Time"
> > # *** wrong switch in 2006 ***
> > as.POSIXct("2006-10-30 12:38:47")+(-4:7)*(24*3600)
> [1] "2006-10-26 12:38:47 Mountain Daylight Time"
> [2] "2006-10-27 12:38:47 Mountain Daylight Time"
> [3] "2006-10-28 12:38:47 Mountain Daylight Time"
> [4] "2006-10-29 12:38:47 Mountain Daylight Time"
> [5] "2006-10-30 12:38:47 Mountain Daylight Time"
> [6] "2006-10-31 12:38:47 Mountain Daylight Time"
> [7] "2006-11-01 12:38:47 Mountain Daylight Time"
> [8] "2006-11-02 12:38:47 Mountain Daylight Time"
> [9] "2006-11-03 12:38:47 Mountain Daylight Time"
> [10] "2006-11-04 12:38:47 Mountain Daylight Time"
> [11] "2006-11-05 11:38:47 Mountain Standard Time"
> [12] "2006-11-06 11:38:47 Mountain Standard Time"
> > as.POSIXct("2007-10-30 12:38:47")+(-4:7)*(24*3600)
> [1] "2007-10-26 12:38:47 Mountain Daylight Time"
> [2] "2007-10-27 12:38:47 Mountain Daylight Time"
> [3] "2007-10-28 12:38:47 Mountain Daylight Time"
> [4] "2007-10-29 12:38:47 Mountain Daylight Time"
> [5] "2007-10-30 12:38:47 Mountain Daylight Time"
> [6] "2007-10-31 12:38:47 Mountain Daylight Time"
> [7] "2007-11-01 12:38:47 Mountain Daylight Time"
> [8] "2007-11-02 12:38:47 Mountain Daylight Time"
> [9] "2007-11-03 12:38:47 Mountain Daylight Time"
> [10] "2007-11-04 11:38:47 Mountain Standard Time"
> [11] "2007-11-05 11:38:47 Mountain Standard Time"
> [12] "2007-11-06 11:38:47 Mountain Standard Time"
> > Sys.setenv(TZ="MST7MDT")
> > Sys.timezone()
> [1] "MST"
> > as.POSIXct("2006-10-30 12:38:47")+(-4:7)*(24*3600)
> [1] "2006-10-26 13:38:47 MDT" "2006-10-27 13:38:47 MDT"
> [3] "2006-10-28 13:38:47 MDT" "2006-10-29 12:38:47 MST"
> [5] "2006-10-30 12:38:47 MST" "2006-10-31 12:38:47 MST"
> [7] "2006-11-01 12:38:47 MST" "2006-11-02 12:38:47 MST"
> [9] "2006-11-03 12:38:47 MST" "2006-11-04 12:38:47 MST"
> [11] "2006-11-05 12:38:47 MST" "2006-11-06 12:38:47 MST"
> > # *** wrong switch in 2007 ***
> > as.POSIXct("2007-10-30 12:38:47")+(-4:7)*(24*3600)
> [1] "2007-10-26 13:38:47 MDT" "2007-10-27 13:38:47 MDT"
> [3] "2007-10-28 12:38:47 MST" "2007-10-29 12:38:47 MST"
> [5] "2007-10-30 12:38:47 MST" "2007-10-31 12:38:47 MST"
> [7] "2007-11-01 12:38:47 MST" "2007-11-02 12:38:47 MST"
> [9] "2007-11-03 12:38:47 MST" "2007-11-04 12:38:47 MST"
> [11] "2007-11-05 12:38:47 MST" "2007-11-06 12:38:47 MST"
> >
>
> I see this behavior on all the Windows systems I have tried:
> Windows XP 64 bit, Windows XP 32 bit Pro, Windows XP home,
> Windows 2000, with a variety of R versions. The systems
> have all relevant Windows updates applied (unless some were
> inadvertently missed) and the systems otherwise appear to
> behave correctly with respect to times and timezones.
>
> I do not see this problem on Ubuntu Linux systems.
>
> -- Tony Plate
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard_at_biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu 01 Nov 2007 - 17:28:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 02 Nov 2007 - 14:30:14 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.