Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

timezones in R: how to avoid ambiguous terms such as EST?

I have a series of character timestamps in R. When I change their class to POSIXct using intuitive methods, R assigns the ambiguous timezone EST.

For example:

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) boxes:

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

The problem here is EST could be any number of timezones: Eastern Standard Time in the USA, or Australian Eastern Standard Time, or another timezone in Canada (from ?timezone):

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

There is a method to set the timezone which avoids this EST label. It is alluded to, but not fully explained in the R ?timezone help. Setting x as the time of the Curiosity landing on Mars as reported by an 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 test that this is correct by converting it to a US timezone and checking with a Californian news report:

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

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

Many systems support timezones of the form GMT+n and GMT-n, which are at a fixed offset from UTC (hence no DST). Contrary to some usage (but consistent with names such as PST8PDT), negative offsets are times ahead of (east of) UTC, positive offsets are times behind (west of) UTC.

like image 866
sfuj Avatar asked Aug 13 '12 02:08

sfuj


1 Answers

The 1st and 3rd lines in your first example produce the same output because tz="" is the default for as.POSIXct. The second line is more interesting because the timezone is explicitly defined.

But note that "EST" is only how the timezone is printed by default. 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"
like image 59
Joshua Ulrich Avatar answered Oct 09 '22 18:10

Joshua Ulrich