[R] timezone problems

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Jul 11 19:37:45 CEST 2005


For the record, this was covered by an answer to your bug report.

The problem is your OS which mishandles a timezone of `GMT', so 
Sys.getenv("TZ") as `GMT' is not actually setting your OS to GMT.
Hence NA is the correct answer.

I know no way to set Windows to GMT as distinct from the timezone of 
London (with summer time).

On Thu, 7 Jul 2005, Martin Keller-Ressel wrote:

> Thank you Don for your hints. I have checked my environment vairable TZ
> again. But everything is set correctly. I think the problem is with
> Sys.timezone(). Maybe it is a conflict between how my system formats the
> time/date and what Sys.timezone() expects.
> This is what I get on my system:
>
>> Sys.getenv("TZ")
>    TZ
> "GMT"
>> Sys.time()
> [1] "2005-07-07 07:32:39 GMT"
>
> ## everything fine so far
>
>> Sys.timezone()
> [1] NA
>
> ## This is what Sys.timezone looks like:
>> Sys.timezone
> function ()
> {
>     z <- as.POSIXlt(Sys.time())
>     attr(z, "tzone")[2 + z$isdst]
> }
> <environment: namespace:base>
>
>> z <- as.POSIXlt(Sys.time())
>> attributes(z)
> $names
> [1] "sec"   "min"   "hour"  "mday"  "mon"   "year"  "wday"  "yday"  "isdst"
>
> $class
> [1] "POSIXt"  "POSIXlt"
>
> $tzone
> [1] "GMT"
>
>> attr(z,"tzone")
> [1] "GMT"
>> z$isdst
> [1] 0
>> attr(z,"tzone")[2]
> [1] NA
>
> I dont understand why Sys.timezone doesn't use attr(z,"tzone") but tries
> to read its (2+z$isdst)-th element.
> Of course it would be easy to write a workaround, but I wonder why nobody
> else is having this problem.
>
> best regards,
>
> Martin Keller-Ressel
>
>
>
> On Wed, 06 Jul 2005 14:45:25 -0000, Don MacQueen <macq at llnl.gov> wrote:
>
>> How did you set the TZ system variable?
>> If you did not use Sys.putenv(), try using it instead.
>> Otherwise, I think you have to ask the package maintainer.
>>
>> You may be misleading yourself by using Sys.time() to test whether TZ is
>> set.
>> What does Sys.getenv() tell you?
>>
>> I get a timezone code from Sys.time() even when TZ is not defined (see
>> example below).
>> (but I do have a different OS)
>>
>>>  Sys.timezone()
>> [1] ""
>>>  Sys.time()
>> [1] "2005-07-06 07:34:15 PDT"
>>>  Sys.getenv('TZ')
>> TZ
>> ""
>>>  Sys.putenv(TZ='US/Pacific')
>>>  Sys.timezone()
>> [1] "US/Pacific"
>>>  Sys.getenv('TZ')
>>            TZ
>> "US/Pacific"
>>>  Sys.time()
>> [1] "2005-07-06 07:34:38 PDT"
>>
>>>  Sys.putenv(TZ='GMT')
>>>  Sys.time()
>> [1] "2005-07-06 14:35:45 GMT"
>>
>>>  version
>>           _                       platform powerpc-apple-darwin7.9.0
>> arch     powerpc                 os       darwin7.9.0
>> system   powerpc, darwin7.9.0    status
>> major    2                       minor    1.1
>> year     2005                    month    06
>> day      20                      language R
>> At 9:55 AM +0000 7/5/05, Martin Keller-Ressel wrote:
>>> Hi,
>>>
>>> Im using R 2.1.1 and running Code that previously worked (on R 2.1.0 I
>>> believe) using the 'timeDate' function from the fCalendar package. The
>>> code now throws an error:
>>>
>>> Error in if (Sys.timezone() != "GMT") warning("Set timezone to GMT!")
>>>
>>> However I have read the documentation of the fCalendar package and I
>>> have set my system variable TZ to GMT.
>>> I tracked the error down to the function Sys.timezone() which returns
>>> NA in spite of what Sys.time() returns.
>>>
>>>>  Sys.timezone()
>>> [1] NA
>>>
>>>>  Sys.time()
>>> [1] "2005-07-05 08:41:53 GMT"
>>>
>>> My version:
>>>
>>>>  version
>>>           _
>>> platform i386-pc-mingw32
>>> arch     i386
>>> os       mingw32
>>> system   i386, mingw32
>>> status
>>> major    2
>>> minor    1.1
>>> year     2005
>>> month    06
>>> day      20
>>> language R
>>>
>>> Any help is appreciated,
>>>
>>> Martin Keller-Ressel
>>>
>>>
>>> ---
>>> Martin Keller-Ressel
>>> Research Unit of Financial and Actuarial Mathematics
>>> TU Vienna
>>>
>>> ______________________________________________
>>> R-help at stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide!
>>> http://www.R-project.org/posting-guide.html
>>
>>
>
>
>
> -- 
> Martin Keller-Ressel
> Research Unit of Financial and Actuarial Mathematics
> TU Vienna
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

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