[R] Unexpected behavior of clocktime related to daylight savings time

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Nov 7 17:05:49 CET 2008


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



More information about the R-help mailing list