Re: [R] timezone problems

From: Martin Keller-Ressel <mkeller_at_fam.tuwien.ac.at>
Date: Fri 08 Jul 2005 - 02:44:20 EST

I cannot reproduce Don's results below on my system. However I do not know if timezone names can be expected to be compatible across systems/country settings/etc...

I get:
> Sys.putenv(TZ='US/Pacific')
> z <- as.POSIXlt(Sys.time())
> attributes(z)$tzone

[1] "\001S/Pacific" "US/" "Pac"

which looks very ugly. I also tried

> Sys.putenv(TZ='MESZ')
> z <- as.POSIXlt(Sys.time())
> attributes(z)$tzone

[1] "\001ESZ" "MES" "Z" which is also probably not intended.
I filed a bug report a few hours ago (#7994) but only pointed out the problems regarding timezone 'GMT' discussed in the last mail, not the 'new' problems associated with setting another timezone.

Martin Keller-Ressel

On Thu, 07 Jul 2005 14:58:46 -0000, Don MacQueen <macq@llnl.gov> wrote:

> ?POSIXt says:
>
> '"POSIXlt"' objects will often have an attribute '"tzone"', a
> character vector of length 3 giving the timezone name from the
> 'TZ' environment variable and the names of the base timezone and
> the alternate (daylight-saving) timezone. Sometimes this may just
> be of length one, giving the timezone name.
>
> Therefore, any function that relies on either
> (1) the presence of a "tzone" attribute, or
> (2) when it is present, it necessarily has a length 3
> is relying on something that is documented not to be reliable.
>
> Sys.timezone(), as defined on Martin's system (see his email below) does
> both of these, so that would appear to be the problem.
>
>
> It is not hard to verify that the tzone attribute is not always present,
> and when present, may be of length one or three.
>
>> Sys.putenv(TZ='US/Pacific')
>> z <- as.POSIXlt(Sys.time())
>> attributes(z)$tzone
> [1] "US/Pacific" "PST" "PDT"
>> Sys.putenv(TZ='GMT')
>> z <- as.POSIXlt(Sys.time())
>> attributes(z)$tzone
> [1] "GMT"
>
>> Sys.putenv(TZ='US/Eastern')
>> z <- as.POSIXlt(Sys.time())
>> attributes(z)$tzone
> [1] "US/Eastern" "EST" "EDT"
>> z <- as.POSIXlt(c('2005-1-1','2005-6-1'))
>> names(attributes(z))
> [1] "names" "class"
>
>
> -Don
>
> At 11:57 AM +0200 7/7/05, Uwe Ligges wrote:
>> 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@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@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
>>>>
>>>>
>>>
>>>
>>>
>>
>> ______________________________________________
>> R-help@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@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
Received on Fri Jul 08 01:37:54 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:20 EST