Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'UTC' equality can be extended to other equivalent time zones #319

MichaelChirico opened this issue Dec 17, 2019 · 2 comments


Copy link

MichaelChirico commented Dec 17, 2019

I just filed this at data.table: Rdatatable/data.table#4117

And this fix for base R:

I notice also several usages of testing UTC value in xts:

xts/R/tzone.R:106:    if (!(tzone(x) %in% c("UTC","GMT")))
xts/R/endpoints.R:133:        Sys.getenv("TZ") %in% c("", "GMT", "UTC"))

If you're amenable, I would file a PR to an equivalent is_utc internal utility & replace the above instances

I also filed a similar issue for lubridate: tidyverse/lubridate#844

Copy link

Thanks for the suggestion! As I noted in the R bugzilla tracker, using switch() seems to be about as fast as checking for equality (e.g. tz == "UTC") and can cover all cases. What do you think of that solution?

in_utc <- function(tz) {
  utc_tz <- c("UTC", "GMT", "Etc/UTC", "Etc/GMT", "GMT-0", "GMT+0", "GMT0")
  if (is.null(tz)) tz <- Sys.timezone()
  return(tz %in% utc_tz)
is_utc <- function(tz) {
  if (is.null(tz)) {
    tz <- Sys.timezone()
         "UTC" = ,
         "GMT" = ,
         "Etc/UTC" = ,
         "Etc/GMT" = ,
         "GMT-0" = ,
         "GMT+0" = ,
         "GMT0" = TRUE,
tzones <- replicate(100, OlsonNames())
system.time(for(tz in tzones) is_utc(tz))  # ~0.035
system.time(for(tz in tzones) in_utc(tz))  # ~0.113

Copy link

Looks great! I wonder why it's faster...

@joshuaulrich joshuaulrich added this to the 0.12-1 milestone Jul 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

2 participants