NoviceProg
NoviceProg

Reputation: 825

R: `lubridate` cannot recognise timezone "SG" in Windows

I've been using R in Debian for 5 years and have always set tz() as "SG" - for 'Singapore'. When I port my code to Windows 8.1 (installed with the latest R 3.6.0 and lubridate 1.7.4), I hit into the following error:

> library(lubridate)
> a <- Sys.time()
> tz(a) <- "SG" 
Error in C_force_tz(time, tz = tzone, roll) :    
    CCTZ: Unrecognized output timezone: "SG"

MY INVESTIGATION

Using my Debian VM, I updated lubridate from v1.6.0 (which has been working fine all along) to the latest v1.7.4, and true enough, it showed the same error.

Thinking that I've found the bug, I went back to Windows and installed lubridate 1.6.0, but lo-and-behold! It hit a similar error:

> library(lubridate)
> a <- Sys.time()
> tz(a)<-"SG"
Warning messages:
1: In as.POSIXct.POSIXlt(lt) : unknown timezone 'SG'
2: In as.POSIXlt.POSIXct(ct) : unknown timezone 'SG'

My Questions

Naturally, my questions are: (i) Why is the above error happening in Debian when I upgraded lubridate to v1.7.4? and (ii) How can I resolve the error in Windows using either lubridate v1.6.0 or v1.7.4?

Last I checked, Singapore is still a country and according to Microsoft Default Timezones, Singapore's timezone is 'SG' (middle of the page).

After all these years, I've never completely understood date/time and timezones. Hope someone wiser than me can help enlighten.

SYSTEM INFO

# Windows 8.1 (where the error occurred)
R: 3.6.0 (64-bit)
lubridate: both 1.6.0 and 1.7.4 give error

# Debian Jessie
R: 3.3.3 (64-bit)
lubridate: 1.6.0 (NO error) and 1.7.4 (has error)

Upvotes: 1

Views: 372

Answers (1)

MrFlick
MrFlick

Reputation: 206606

You can get a list of "official" timezone names from the OlsonNames() function. It doesn't look like country codes like "SG" are on that list, but "Singapore" is. So you can do

tz(a) <- "Singapore"

Upvotes: 2

Related Questions