[R] how to calculate time offset between timezones?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Jan 10 17:13:49 CET 2008
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:
https://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, 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