Dennis Fisher
2008-Nov-07 13:45 UTC
[R] Unexpected behavior of clocktime related to daylight savings time
Colleagues, I submitted this several days ago and no one responded, so I am trying again, trying a different subject line: I just encountered some unexpected behavior of difftime in relationship to the change from daylight savings to standard time. My understanding is that DST and ST take effect at 2AM. However, the results below suggests that R (version 2.8.0 in OS X) implements the change at 2:16AM: Expected:> > difftime("2008-11-02 02:01:00", "2008-11-02 00:59:00") > Time difference of 2.033333 hours > > difftime("2008-11-02 01:16:00", "2008-11-02 01:15:00") > Time difference of 1 mins > > difftime("2008-11-02 01:18:00", "2008-11-02 01:17:00") > Time difference of 1 minsNot expected:> > difftime("2008-11-02 01:17:00", "2008-11-02 01:16:00") > Time difference of 1.016667 hoursCan anyone explain this? Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-415-564-2220 www.PLessThan.com [[alternative HTML version deleted]]
Prof Brian Ripley
2008-Nov-07 16:05 UTC
[R] Unexpected behavior of clocktime related to daylight savings time
On Fri, 7 Nov 2008, Dennis Fisher wrote:> Colleagues, > > I submitted this several days ago and no one responded, so I am trying > again, trying a different subject line:Well, you posted something that indicated you had not studied the relevant help pages, without the information requested in the R posting guide, and with an HTML posting.> I just encountered some unexpected behavior of difftime in > relationship to the change from daylight savings to standard time. > > My understanding is that DST and ST take effect at 2AM. However, the > results below suggests that R (version 2.8.0 in OS X) implements the > change at 2:16AM:The transition time depends on the country (and in some cases, the year). In the EU it is at 2am (and always has been, not that the EU is very old).> Expected: >>> difftime("2008-11-02 02:01:00", "2008-11-02 00:59:00") >> Time difference of 2.033333 hours >>> difftime("2008-11-02 01:16:00", "2008-11-02 01:15:00") >> Time difference of 1 mins >>> difftime("2008-11-02 01:18:00", "2008-11-02 01:17:00") >> Time difference of 1 mins > > Not expected: >>> difftime("2008-11-02 01:17:00", "2008-11-02 01:16:00") >> Time difference of 1.016667 hours > > Can anyone explain this?Yes, and you should have been able to do so from the information in the help pages. As ?strptime says Remember that in most timezones some times do not occur and some occur twice because of transitions to/from summer time. What happens in those cases is OS-specific. See also the note on ?Sys.timezone. No OS I tried did this, not even Mac OS X set to EST5EDT. But in EST5EDT 2008-11-02 01:17:00 occurred twice:> as.POSIXct("2008-11-02 01:17:00")[1] "2008-11-02 01:17:00 EDT"> as.POSIXct("2008-11-02 01:17:00") + 3600[1] "2008-11-02 01:17:00 EST" so 1.016667 hours would be one of two correct answers in that timezone. However, you didn't tell us what timezone you are in and hence we cannot know when DST transitions occur in that timezone.> > Dennis > > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone: 1-866-PLessThan (1-866-753-7784) > Fax: 1-415-564-2220 > www.PLessThan.com-- 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
Thomas Lumley
2008-Nov-09 22:51 UTC
[R] Unexpected behavior of clocktime related to daylight savings time
I'm not surprised that strange things happen if you try to handle times in the duplicated hour without specifying which time you mean. If your current time zone setting is something like EST5EDT that includes both daylight-saving and standard times then 2008-11-02 01:16:00 occured twice, so some of the calls to difftime() are ambiguous. If your time-zone setting specifies daylight-saving time or not, then some of the calls to difftime() involve times that did not exist. If you create POSIXt objects that unambiguously specify the times then things should be more predictable. -thomas On Fri, 7 Nov 2008, Dennis Fisher wrote:> Colleagues, > > I submitted this several days ago and no one responded, so I am trying > again, trying a different subject line: > > I just encountered some unexpected behavior of difftime in > relationship to the change from daylight savings to standard time. > > My understanding is that DST and ST take effect at 2AM. However, the > results below suggests that R (version 2.8.0 in OS X) implements the > change at 2:16AM: > > Expected: >>> difftime("2008-11-02 02:01:00", "2008-11-02 00:59:00") >> Time difference of 2.033333 hours >>> difftime("2008-11-02 01:16:00", "2008-11-02 01:15:00") >> Time difference of 1 mins >>> difftime("2008-11-02 01:18:00", "2008-11-02 01:17:00") >> Time difference of 1 mins > > Not expected: >>> difftime("2008-11-02 01:17:00", "2008-11-02 01:16:00") >> Time difference of 1.016667 hours > > Can anyone explain this? > > Dennis > > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone: 1-866-PLessThan (1-866-753-7784) > Fax: 1-415-564-2220 > www.PLessThan.com > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle
Seemingly Similar Threads
- Unexpected behavior of difftime in relationship to daylight savings time
- RODBC & POSIX & Daylight Saving blues
- daylight saving / time zone issues with as.POSIXlt/as.POSIXct (PR#10392)
- POSIXct time zone and daylight savings issues
- Fwd: [musl] strptime() question