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

Dennis Fisher fisher at plessthan.com
Sat Nov 8 16:49:18 CET 2008


Professor Ripley,

My apologies for not clarifying the timezone - I am in California (PDT  
-> PST).   I did review various help pages and I am still unclear on  
the explanation.

I replicated your code:
> > as.POSIXct("2008-11-02 01:17:00")
> [1] "2008-11-02 01:17:00 PST"
> > as.POSIXct("2008-11-02 01:17:00") + 3600
> [1] "2008-11-02 02:17:00 PST"
Your second command yielded 1:17; mine yielded 2:17.

On my OS X machine (R 2.8.0):
> > Sys.timezone()
> [1] ""
i.e., Sys.timezone returns an empty string.

So, the question remains: is this an OS issue or an R issue (i.e., my  
"difftime" commands below appear to show that DST takes effect as  
1:16, not 1:100)?

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

On Nov 7, 2008, at 8:05 AM, Prof Brian Ripley wrote:

> 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
>
> -- 
> 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