#QUESTION# Is there a way to calculate the offset between timezones, e.g. from "AST" to "GMT"? #DETAILS# I am working with data files that use local time, and that indicate the timezone by e.g. "AST" (Atlantic Standard Time, my local time) in a header. I was guessing that> ISOdatetime(2008,1,1,1,0,0,tz="GMT") - > ISOdatetime(2008,1,1,1,0,0,tz="AST")would work, but it gives a difference of 0. However, when I do> ISOdatetime(2008,1,1,1,0,0,tz="GMT") - ISOdatetime(2008,1,1,1,0,0)I get a -4h offset, which is correct. The odd thing is, I am in AST time, as shown by the following.> ISOdatetime(2008,1,1,1,0,0)[1] "2008-01-01 01:00:00 AST" #SYSTEM# Mac OS X system, with R 2.6.1 #PS# I am aware that this sort of thing is system dependent, and so there may not be a general solution. But even if I can only get it working on my own particular system, I'd be happy! -- View this message in context: nabble.com/how-to-calculate-time-offset-between-timezones--tp14736453p14736453.html Sent from the R help mailing list archive at Nabble.com.
well, strangely, ISOdatetime(2008,1,1,1,0,0,tz="AST") creates a UTC timezone date on my system:> ISOdatetime(2008,1,1,1,0,0,tz="AST")[1] "2008-01-01 01:00:00 UTC">and if you compare the numeric values of the UTC datetime and the GMT datetime, the are definitely the same:> as.numeric(ISOdatetime(2008,1,1,1,0,0,tz="AST"))[1] 1199149200> as.numeric(ISOdatetime(2008,1,1,1,0,0,tz="GMT"))[1] 1199149200>I think the failure to recognize AST may have something to with the timzones listed in /usr/share/zoneinfo (on Ubuntu linux) where I found AST4: whit at spartan:~$ find /usr/share/zoneinfo -name "AST*" /usr/share/zoneinfo/SystemV/AST4 /usr/share/zoneinfo/SystemV/AST4ADT /usr/share/zoneinfo/right/SystemV/AST4 /usr/share/zoneinfo/right/SystemV/AST4ADT /usr/share/zoneinfo/posix/SystemV/AST4 /usr/share/zoneinfo/posix/SystemV/AST4ADT and when I use it as the tz argument:> ISOdatetime(2008,1,1,1,0,0,tz="AST4")[1] "2008-01-01 01:00:00 AST">and> ISOdatetime(2008,1,1,1,0,0,tz="AST4") -ISOdatetime(2008,1,1,1,0,0,tz="GMT") Time difference of 4 hours>-Whit> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of dankelley > Sent: Thursday, January 10, 2008 10:21 AM > To: r-help at r-project.org > Subject: [R] how to calculate time offset between timezones? > > > #QUESTION# > > Is there a way to calculate the offset between timezones, > e.g. from "AST" to "GMT"? > > #DETAILS# > > I am working with data files that use local time, and that > indicate the timezone by e.g. "AST" (Atlantic Standard Time, > my local time) in a header. > I was guessing that > > > ISOdatetime(2008,1,1,1,0,0,tz="GMT") - > > ISOdatetime(2008,1,1,1,0,0,tz="AST") > > would work, but it gives a difference of 0. However, when I do > > > ISOdatetime(2008,1,1,1,0,0,tz="GMT") - ISOdatetime(2008,1,1,1,0,0) > > I get a -4h offset, which is correct. The odd thing is, I am > in AST time, as shown by the following. > > > ISOdatetime(2008,1,1,1,0,0) > [1] "2008-01-01 01:00:00 AST" > > #SYSTEM# > > Mac OS X system, with R 2.6.1 > > #PS# > > I am aware that this sort of thing is system dependent, and > so there may not be a general solution. But even if I can > only get it working on my own particular system, I'd be happy! > -- > View this message in context: > nabble.com/how-to-calculate-time-offset-between-tim > ezones--tp14736453p14736453.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >This e-mail message is intended only for the named recipient(s) above. It may contain confidential information. If you are not the intended recipient you are hereby notified that any dissemination, distribution or copying of this e-mail and any attachment(s) is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by replying to this e-mail and delete the message and any attachment(s) from your system. Thank you.
Prof Brian Ripley
2008-Jan-10 16:13 UTC
[R] how to calculate time offset between timezones?
On Thu, 10 Jan 2008, dankelley wrote:> > #QUESTION# > > Is there a way to calculate the offset between timezones, e.g. from "AST" to > "GMT"? > > #DETAILS# > > I am working with data files that use local time, and that indicate the > timezone by e.g. "AST" (Atlantic Standard Time, my local time) in a header.The problem is that AST is not a valid timezone (at least on my Mac), so is being ignored. I think you want "America/Halifax". (Works for me on Leopard as well as on Linux.) The documentation for R-devel may help here: svn.r-project.org/R/trunk/src/library/base/man/timezones.Rd But earlier versions do say things like If a timezone is needed and that specified is invalid on your system, what happens is system-specific but it will probably be ignored.> I was guessing that > >> ISOdatetime(2008,1,1,1,0,0,tz="GMT") - >> ISOdatetime(2008,1,1,1,0,0,tz="AST") > > would work, but it gives a difference of 0. However, when I do > >> ISOdatetime(2008,1,1,1,0,0,tz="GMT") - ISOdatetime(2008,1,1,1,0,0) > > I get a -4h offset, which is correct. The odd thing is, I am in AST time, > as shown by the following. > >> ISOdatetime(2008,1,1,1,0,0) > [1] "2008-01-01 01:00:00 AST" > > #SYSTEM# > > Mac OS X system, with R 2.6.1 > > #PS# > > I am aware that this sort of thing is system dependent, and so there may not > be a general solution. But even if I can only get it working on my own > particular system, I'd be happy! >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, 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