R: `lubridate` 无法识别 Windows 中的时区 "SG"

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

我在 Debian 中使用 R 已经 5 年了,并且总是将 tz() 设置为 "SG" - 对于 'Singapore'。当我将我的代码移植到 Windows 8.1(安装了最新的 R 3.6.0 和 lubridate 1.7.4)时,我遇到了以下错误:

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

我的调查

使用我的 Debian VM,我将 lubridate 从 v1.6.0(一直运行良好)更新到最新的 v1.7.4,果然,它显示了同样的错误。

以为我已经找到了这个错误,我回到 Windows 并安装了 lubridate 1.6.0,但是瞧瞧!它遇到了类似的错误:

> 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'

我的问题

当然,我的问题是: (i) 为什么我将lubridate 升级到v1.7.4 后,Debian 会出现上述错误?和 (ii) 如何使用 lubridate v1.6.0 或 v1.7.4 解决 Windows 中的错误?

我最后查了一下,新加坡仍然是一个国家,根据 Microsoft Default Timezones,新加坡的时区是 'SG'(页面中间)。

这么多年过去了,我从未完全理解 date/time 和时区。希望有比我聪明的人帮忙指教

系统信息

# 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)

您可以从 OlsonNames() 函数中获取 "official" 时区名称的列表。 "SG" 之类的国家/地区代码似乎不在该列表中,但 "Singapore" 却在。所以你可以做

tz(a) <- "Singapore"