IAGO GINÉ VÁZQUEZ
2020-Oct-23 17:03 UTC
[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]]
IAGO GINÉ VÁZQUEZ
2020-Oct-23 17:27 UTC
[Rd] The presence/absence of `zone` in POSIXlt depending on time zone as a cause of possible inconsistences?
?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 at r-project.org> de part de IAGO GIN? V?ZQUEZ <i.gine at pssjd.org> Enviat el: divendres, 23 d?octubre de 2020 19:03 Per a: r-devel at r-project.org <r-devel at 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 at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel [[alternative HTML version deleted]]
Sebastian Meyer
2020-Oct-23 19:58 UTC
[Rd] The presence/absence of `zone` in POSIXlt depending on time zone as a cause of possible inconsistences?
Hi Iago, I think the unlist behaviour is expected. If the list contains a mixture of character and integer elements, the unlisted object will be a character vector, similar to what happens when you c()oncatenate components of different types (see the details in ?c for the hierarchy). If you only need the numeric POSIXlt components anyway, you could do unlist("$<-"(x, "zone", NULL)) to ensure that you get a numeric vector. Alternatively, you can nicely do as.data.frame(unclass(x)) to get all components in a data frame. Concerning your second observation: Yes, the documentation of the "tzone" attribute was wrong until very recently; I stumbled over this exact trap one week ago and reported to R-core members. It has been fixed in the development version (c79351) a few days ago and now says:> a character vector of length 3 giving the time zone name (from the 'TZ' > environment variable or argument 'tz' of functions creating > '"POSIXlt"' objects; '""' marks the current time zone)Best regards, Sebastian Am 23.10.20 um 19:27 schrieb IAGO GIN? V?ZQUEZ:> ?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 at r-project.org> de part de IAGO GIN? V?ZQUEZ <i.gine at pssjd.org> > Enviat el: divendres, 23 d?octubre de 2020 19:03 > Per a: r-devel at r-project.org <r-devel at 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 at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Dr. Sebastian Meyer Friedrich-Alexander-Universit?t Erlangen-N?rnberg (FAU) Institut f?r Medizininformatik, Biometrie und Epidemiologie (IMBE) Tel. +49 9131 85-22707