[R] timezone problems

Uwe Ligges ligges at statistik.uni-dortmund.de
Thu Jul 7 11:57:42 CEST 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.


I can confirm for R-2.1.1 under Windows NT 4.0 and it looks like a bug 
(somewhere down the way from as.POSIXlt). Don't have the time to look at 
it more closely, perhaps Brian knows it at once?
If this is not already in the bug repository (please check at first), 
can you submit a report, please? Thanks!

Uwe Ligges





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




More information about the R-help mailing list