Timezones in R: how to avoid ambiguous terms like EST?

I have a series of character timestamps in R. When I change my class to POSIXct using intuitive methods, R assigns an indefinite time zone to EST .

For instance:

 as.POSIXct("2012-08-06 15:32:00") as.POSIXct("2012-08-06 15:32:00", tz = "Australia/Brisbane") as.POSIXct("2012-08-06 15:32:00", tz = "") 

all produce the same output on my two (Mac and Windows):

 "2012-08-06 15:32:00 EST" 

The problem here is EST can be any number of time zones: Eastern Standard Time in the USA or Australian Eastern Standard Time or another time zone in Canada (from ?timezone ):

Beware that some of these designations may not be what you think: special EST is the time zone used in Canada without daylight saving time, not EST5EDT and (Australian) Eastern Standard Time.

There is a time zone setting method that avoids this EST mark. This is implied but not fully explained in the R ?timezone help. Setting x as the time of Curiosity's departure to Mars, reported by the Australian news service :

 x <- as.POSIXct("2012-08-06 15:32:00", tz = "Etc/GMT-10") x "2012-08-06 15:32:00 GMT-10" 

And we can verify that this is correct by translating it into the US time zone and checking using the California News Report :

 y <- format(x, tz = "America/Los_Angeles") y "2012-08-05 22:32:00" 

If you use this notation Etc/GMT+n or Etc/GMT-n , beware of the following caveat from ?timezone :

Many systems support time zones of the form GMT + n and GMT-n, which are at a fixed offset from UTC (therefore, there is no DST). Contrary to some usage (but according to names like PST8PDT), negative offsets are times ahead (east of) UTC, positive offsets are behind (west of) UTC.

+6
source share
1 answer

The first and third lines in your first example produce the same output, because tz="" is the default value for as.POSIXct . The second line is more interesting because the time zone is explicitly defined.

But note that "EST" is just the way the time zone is printed clockwise. The tzone attribute is still unambiguous.

 R> x <- as.POSIXct("2012-08-06 15:32:00", tz="Australia/Brisbane") R> x [1] "2012-08-06 15:32:00 EST" R> attr(x, "tzone") [1] "Australia/Brisbane" 
+6
source

Source: https://habr.com/ru/post/922694/


All Articles