Understanding timezone strings in R

Understanding timezone strings in R

The time zones specified must be those from the IANA TZ Database. You can find a list of all supported time zones here. CEST is not on the list.

In general, identifiers in the TZDB consists of the following forms:

  • Location based zones, in the form Area/Locality, such as America/Los_Angeles, Europe/Paris, or Pacific/Honolulu.
    • This is the most prefered format, which you should be using whenever possible.
    • Some have more than two parts, such as America/Indiana/Knox
  • Administrative zones with fixed offsets, such a Etc/UTC, Etc/GMT-3 or Etc/GMT+5.
    • Other than UTC and GMT, these are primarily used for ships at sea. They are almost never needed on land.
    • The offsets in these strings have their sign inverted, for legacy reasons.
  • Older country-specific zones, such as US/Central, Canada/Atlantic, and Egypt.
    • These should be considered deprecated. They used to be zone entries a long time ago, but are now just links for backwards compatibility.
  • A few of the more popular POSIX-style time zones, such as EST5EDT.
    • Also for backwards compatibility. Dont use these.
    • See the section on posix time zones in the timezone tag wiki for details.
  • A few common time zone abbreviations, such as CET and EST.
    • Again, dont use these.
    • See this list on Wikipedia and notice how there are many duplicate entries, making abbreviations somewhat ambiguous. For example, CST might be Central Standard Time in North America, or it might belong to Cuba, China or Australia.
    • Even though CEST may not seem ambiguous at first, consider that many different IANA time zones use the same abbreviation, even though they may have differed at some point in their history.

CEST probably stands for Central European Summer Time.
So during daylight saving time, CET becomes CEST, and in winter it does not:

as.POSIXct(c(2016-1-1 13:00, 2016-3-1 13:00,
             2016-5-1 13:00, 2016-6-1 13:00,
             2016-9-1 13:00,2016-11-1 13:00), tz=CET) 

returns:

 2016-01-01 13:00:00 CET 2016-03-01 13:00:00 CET  2016-05-01 13:00:00 CEST  
 2016-06-01 13:00:00 CEST 2016-09-01 13:00:00 CEST 2016-11-01 13:00:00 CET

However, as @Matt_Johnson explained, CEST is not on official timezone,
so as.POSIXct(2016-1-1 13:00, tz=CEST) fails.

What does remain strange, that CEST is acceptable in a string, even if the time is outside daylight saving time:

as.POSIXct(2016-1-1 13:00 CEST)
[1] 2016-01-01 13:00:00 CET

The help files from as.POSIXct and strptime dont offer any explaination here.

Understanding timezone strings in R

Sometimes I wish the world would only use a single standard in units of measure, be it time, length, temperature, etc. But until that day, this link from rstudio is one of the best write-up on dealing with time: https://rstudio-pubs-static.s3.amazonaws.com/28038_1bcb9aa80ca84f27ace07d612872861a.html

Specifically to your question

library(lubridate)
x <- as.POSIXct(2016-05-1 10:15:21, tz = America/New_York)
with_tz(x, tz=Europe/Berlin)
[1] 2016-05-01 16:15:21 CEST

Leave a Reply

Your email address will not be published. Required fields are marked *