[R] timezones

james.holtman@convergys.com james.holtman at convergys.com
Mon Aug 4 00:33:11 CEST 2003


Part of the problem is that 'now' is POSIXct and 'now.gmt' is POSIXlt.  If
you use as.POSIXct, you get the right answer.

> (now <- Sys.time())
[1] "2003-08-03 18:29:38 EDT"
> str(now)
`POSIXct', format: chr "2003-08-03 18:29:38"
> (now.gmt <- as.POSIXlt(now,tz="GMT"))
[1] "2003-08-03 22:29:38 GMT"
> str(now.gmt)
`POSIXlt', format: chr "2003-08-03 22:29:38"
> (now.gmt <- as.POSIXct(now,tz="GMT"))
[1] "2003-08-03 18:29:38 EDT"
> str(now.gmt)
`POSIXct', format: chr "2003-08-03 18:29:38"
> now-now.gmt
Time difference of 0 secs
>
__________________________________________________________
James Holtman        "What is the problem you are trying to solve?"
Executive Consultant  --  Office of Technology, Convergys
james.holtman at convergys.com
(513) 723-2929


                                                                                                                   
                      Jerome Asselin                                                                               
                      <jerome at hivnet.ubc.ca        To:       ggrothendieck at volcanomail.com,                        
                      >                             r-help at stat.math.ethz.ch                                       
                      Sent by:                     cc:                                                             
                      r-help-bounces at stat.m        Subject:  Re: [R] timezones                                     
                      ath.ethz.ch                                                                                  
                                                                                                                   
                                                                                                                   
                      07/31/2003 12:30                                                                             
                                                                                                                   
                                                                                                                   





I share your concerns regarding Problems 1 and 2. However, I am unable to
provide help on those at this moment.

As for Problem 3, an alternative for the time being would be to use
another package such as chron or date, although it would be preferable to
use the classes of the base package if possible.

Sorry I can't be more helpful.

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
> more info in it.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help




--
"NOTICE:  The information contained in this electronic mail ...{{dropped}}




More information about the R-help mailing list