[Rd] The presence/absence of `zone` in POSIXlt depending on time zone as a cause of possible inconsistences?
IAGO GINÉ VÁZQUEZ
|@g|ne @end|ng |rom p@@jd@org
Fri Oct 23 19:27:56 CEST 2020
Hi again,
I take advantage of my previous mail to ask you a question for which I was looking for an answer when detected the behaviour I previously told. In the help of DataTimeClasses one can read:
"POSIXlt" objects will often have an attribute "tzone", a character vector of length 3 giving the time zone name from the TZ environment variable and the names of the base time zone and the alternate (daylight-saving) time zone. Sometimes this may just be of length one, giving the time zone name.
Then, I asked myself if the element `zone` of POSIXlt could be different of the attribute `tzone`. But I do not get that. I am not sure of understanding what the "time zone name from the TZ environment variable" is if not what I set through `Sys.setenv(TZ = "")`. But the next example does not behave as I would expect:
> Sys.setenv(TZ = "EDT")
> x <- as.POSIXlt(Sys.time(), "CET")
> x[1,"zone"]
[1] "CEST"
> attributes(x) $names [1] "sec" "min" "hour" "mday" "mon" "year" "wday" "yday" "isdst" "zone" "gmtoff" $class [1] "POSIXlt" "POSIXt" $tzone [1] "CET" "CET" "CEST"
So `x[1,"zone"]` is what I expect, but I would expect `attributes(x)$tzone` would be related to `TZ = "EDT"`, and not to `tz = "CET"`. So, what am I understanding wrongly?
Thank you!
Stay safe,
Iago
________________________________
De: R-devel <r-devel-bounces using r-project.org> de part de IAGO GINÉ VÁZQUEZ <i.gine using pssjd.org>
Enviat el: divendres, 23 d’octubre de 2020 19:03
Per a: r-devel using r-project.org <r-devel using r-project.org>
Tema: [Rd] The presence/absence of `zone` in POSIXlt depending on time zone as a cause of possible inconsistences?
Dear all,
I have just detected what seems a minor inconsistence with data types. If one unlists a POSIXlt time with GMT zone gets a numeric vector, since the POSIXlt list has no `zone` element, while if one unlists a POSIXlt time with a non GMT zone (also non specifying tz if the Sys.timezone is not GMT) gets a character vector due to including the `zone` element.
> x <- as.POSIXlt(Sys.time(), "GMT")
> (y <- unlist(x))
sec min hour mday mon year wday yday isdst
54.99715 26.00000 16.00000 23.00000 9.00000 120.00000 5.00000 296.00000 0.00000
> str(y)
Named num [1:9] 55 26 16 23 9 ...
- attr(*, "names")= chr [1:9] "sec" "min" "hour" "mday" ...
> x <- as.POSIXlt(Sys.time(), "CET")
> (y <- unlist(x))
sec min hour mday mon year wday yday
"19.5111262798309" "27" "18" "23" "9" "120" "5" "296"
isdst zone gmtoff
"1" "CEST" "7200"
> str(y)
Named chr [1:11] "19.5111262798309" "27" "18" "23" "9" "120" "5" "296" "1" "CEST" "7200"
- attr(*, "names")= chr [1:11] "sec" "min" "hour" "mday" ...
Is it expected? Why do not include always `zone` as an element of POSIXlt? Should POSIXlt objects be unlisted in a different way?
Thank you!
Best regards,
Iago
PS: I was using R 4.0.3. I don't know if this behaviour already changed in R-devel. Excuse me in that case.
[[alternative HTML version deleted]]
______________________________________________
R-devel using r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
[[alternative HTML version deleted]]
More information about the R-devel
mailing list