# [R] timezones

Jerome Asselin jerome at hivnet.ubc.ca
Sat Aug 2 00:12:59 CEST 2003

```Hi Gabor,

Both have something to do with the daylight vs. standard times. If I
understand correctly, "GMT" has only standard time.

Consider this example.

> (now <- Sys.time())
[1] "2003-08-01 15:03:38 PDT"
> (now.gmt <- as.POSIXlt(now,tz="GMT"))
[1] "2003-08-01 22:03:38 GMT"
> now-now.gmt
Time difference of -8 hours

One might rather expect -7 hours, but if you add 6 months to both date
objects, then we have:

> (now2 <- Sys.time()+60*60*24*366/2)
[1] "2004-01-31 14:03:38 PST"
> (now2.gmt <- as.POSIXlt(now2,tz="GMT"))
[1] "2004-01-31 22:03:38 GMT"
> now2-now2.gmt
Time difference of -8 hours

Which is correct. Note the change from "15:03:38 PDT" to "14:03:38 PST".

I hope this helped you understand what was happening and how to use the

Cheers,
Jerome

On July 30, 2003 09:19 pm, Gabor Grothendieck wrote:
> I have some questions and comments on timezones.
>
> Problem 1.
>
> # get current time in current time zone
>
> > (now <- Sys.time())
>
> [1] "2003-07-29 18:23:58 Eastern Daylight Time"
>
> # convert this to GMT
>
> > (now.gmt <- as.POSIXlt(now,tz="GMT"))
>
> [1] "2003-07-29 22:23:58 GMT"
>
> # take difference
>
> > now-now.gmt
>
> Time difference of -5 hours
>
> Note that the difference between the times displayed by the first two
> R expressions is -4 hours.  Why does the last expression return
> -5 hours?
>
>
> Problem 2.  Why do the two expressions below give different answers?
> I take the difference between two dates in GMT and then repeat it in the
> current time zone (EDT).
>
> # days since origin in GMT
>
> > julian(as.POSIXct("2003-06-29",tz="GMT"),origin=as.POSIXct("1899-12-30
> >",tz="GMT"))
>
> Time difference of 37801 days
>
> # days since origin in current timezone
>
> > julian(as.POSIXct("2003-06-29"),origin=as.POSIXct("1899-12-30"))
>
> Time difference of 37800.96 days
>
>
> I thought this might be daylight savings time related but even with
>
> standard time I get:
> > julian(as.POSIXct("2003-06-29",tz="EST"),origin=as.POSIXct("1899-12-30
> >",tz="EST"))
>
> Time difference of 37800.96 days
>
>
> Problem 3. What is the general strategy of dealing with dates, as
> opposed to datetimes, in R?
>
> I have had so many problems and a great deal of frustration, mostly
> related to timezones.
>
> The basic problem is that various aspects of the date such as the year,
> the month, the day of the month, the day of the week can be different
> depending on the timezone you use.  This is highly undesirable since
> I am not dealing with anything more granular than a day yet timezones,
> which are completely extraneous to dates and by all rights should not
> have to enter into my problems, keep fowling me up.
>
> A lesser problem is that I find myself using irrelevant constants such
> as the number of seconds in a day which you would think would be
> something I would not have to deal with since I am concerned with daily
> data.
>
> With R have nifty object oriented features I think a good project would
> be to implement a class in the base that handled dates without times
> (or timezones!)
>
> P.S. I have sent an earlier version of this but did not see it posted
> so if both get posted please ignore the prior one since this one has