【发布时间】:2015-08-25 18:21:16
【问题描述】:
我开始在 R 中使用 lubridate 包。我注意到 now(tzone="EST") 计算为:
[1] "2015-08-25 13:01:08 EST"
而now(tzone="PST") 导致警告:
[1] "2015-08-25 18:02:16 GMT"
Warning message:
In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'PST'
那么已知时区是什么?Valid Timezones in Lubridate 有答案。但我想看看我如何为自己回答这个问题(即,通过挖掘包本身)。我看now()函数:
> now
function (tzone = "")
with_tz(Sys.time(), tzone)
<environment: namespace:lubridate>
那么我看with_tz函数:
> with_tz
function (time, tzone = "")
{
check_tz(tzone)
if (is.POSIXlt(time))
new <- as.POSIXct(time)
else new <- time
attr(new, "tzone") <- tzone
reclass_date(new, time)
}
<environment: namespace:lubridate>
>
然后我检查check_tz函数:
> check_tz
Error: object 'check_tz' not found
没有。我在本地lubridate R 库文件中搜索check_tz。我什么也没找到。我进行谷歌搜索并找到this GitHub page。就在那里! olson_time_zones() 似乎列出了已知时区。 (更新:olson_time_zones() 仅返回可用时区的子集。有关更多详细信息,请参阅下面的我的 cmets。)特别是,
> now(tzone="America/Los_Angeles")
[1] "2015-08-25 11:11:14 PDT"
问:如果在 GitHub 上没有很好的文件或在 StackOverflow 上发布答案,我怎么能回答关于已知时区列表的问题?换句话说,我可以通过挖掘本地的lubridate 库文件找到答案吗?
问:有没有更一般的原则来挖掘 R 包,值得指出?
【问题讨论】:
-
我也想知道如何在 R 中找到这类东西。特别是,这里是您问题的一个特别线索。 stackoverflow.com/questions/29784310/…
-
我认为可能会发生,因为现在(8 月下旬)始终是太平洋夏令时间 (PDT),而在一年中的这个时候是太平洋标准时间 (PST)不存在。只是一个想法,不知道它是否正确。
-
@RichardScriven,我认为更奇怪的是,“EST”完全有效,因为
stringr::str_subset(olson_time_zones(), "EST")什么也没返回。看来lubridate也将OlsonNames()用于tzone。str_subset(OlsonNames(), "EST")返回“EST”和“EST5EDT”。str_subset(OlsonNames(), "PDT")返回“PST8PDT”。 -
附注,从 lubridate 1.6(2016 年 9 月)开始,不再有
olson_time_zones- 'here和olson_time_zones分别被new和 baseOlsonNames弃用。'