我一直在处理调整夏令时的解析时间戳,并观察到一些奇怪的行为......即,as.POSIXct
和strptime
在回滚时间内不会产生一致的行为。
更具体地,"11/2/2014 1:45:15 AM"
变为"2014-11-02 01:45:15 PDT"
,"11/2/2014 1:50:00 AM"
变为"2014-11-02 01:50:00 PST"
。我不确定这是否是某种错误,但在我看来应该不会发生。换句话说,在相关时间内解析时间戳时应该有一些一致的行为。
以下块应重现所描述的行为
test_series = c("11/1/2014 11:56:30 PM","11/2/2014 12:26:30 AM",
"11/2/2014 12:41:30 AM","11/2/2014 12:42:30 AM",
"11/2/2014 1:12:30 AM","11/2/2014 1:42:30 AM",
"11/2/2014 1:44:15 AM","11/2/2014 1:45:15 AM",
"11/2/2014 1:15:15 AM","11/2/2014 1:45:15 AM",
"11/2/2014 1:50:00 AM","11/2/2014 1:51:00 AM",
"11/2/2014 2:03:45 AM","11/2/2014 2:04:45 AM",
"11/2/2014 2:23:30 AM","11/2/2014 2:24:30 AM")
format_str="%m/%d/%Y %I:%M:%S %p"
tz_str="US/Pacific"
as.POSIXct(test_series, format=format_str, tz=tz_str)
strptime(test_series, format=format_str, tz=tz_str)
当然,一个明显的解决方法是将时区参数设置为UTC,然后改变时间。但是,我想了解为什么行为不一致。换句话说,我想知道为什么小时的一部分映射到夏令时,另一部分映射到标准。更重要的是,我想控制这种行为。
这是另一个测试字符串数组,具有更高的粒度时间戳......
second_test_series = c('11/1/2015 12:59:30 AM','11/1/2015 1:00:30 AM','11/1/2015 1:01:30 AM','11/1/2015 1:02:30 AM','11/1/2015 1:03:30 AM','11/1/2015 1:04:30 AM','11/1/2015 1:05:30 AM','11/1/2015 1:06:30 AM','11/1/2015 1:07:35 AM','11/1/2015 1:08:35 AM','11/1/2015 1:09:35 AM','11/1/2015 1:10:35 AM','11/1/2015 1:11:35 AM','11/1/2015 1:12:40 AM','11/1/2015 1:13:40 AM','11/1/2015 1:14:40 AM','11/1/2015 1:15:40 AM','11/1/2015 1:16:40 AM','11/1/2015 1:17:40 AM','11/1/2015 1:18:40 AM','11/1/2015 1:19:40 AM','11/1/2015 1:20:40 AM','11/1/2015 1:21:40 AM','11/1/2015 1:22:40 AM','11/1/2015 1:23:40 AM','11/1/2015 1:24:40 AM','11/1/2015 1:25:40 AM','11/1/2015 1:26:40 AM','11/1/2015 1:27:40 AM','11/1/2015 1:28:40 AM','11/1/2015 1:29:40 AM','11/1/2015 1:30:40 AM','11/1/2015 1:31:40 AM','11/1/2015 1:32:45 AM','11/1/2015 1:33:45 AM','11/1/2015 1:34:45 AM','11/1/2015 1:35:45 AM','11/1/2015 1:36:45 AM','11/1/2015 1:37:45 AM','11/1/2015 1:38:50 AM','11/1/2015 1:39:50 AM','11/1/2015 1:40:50 AM','11/1/2015 1:41:50 AM','11/1/2015 1:42:50 AM','11/1/2015 1:43:50 AM','11/1/2015 1:44:50 AM','11/1/2015 1:45:50 AM','11/1/2015 1:46:50 AM','11/1/2015 1:47:50 AM','11/1/2015 1:48:50 AM','11/1/2015 1:49:50 AM','11/1/2015 1:50:50 AM','11/1/2015 1:51:50 AM','11/1/2015 1:52:50 AM','11/1/2015 1:53:50 AM','11/1/2015 1:54:50 AM','11/1/2015 1:55:50 AM','11/1/2015 1:56:50 AM','11/1/2015 1:57:55 AM','11/1/2015 1:58:55 AM','11/1/2015 1:59:55 AM','11/1/2015 1:00:55 AM','11/1/2015 1:01:55 AM','11/1/2015 1:02:55 AM','11/1/2015 1:04:00 AM','11/1/2015 1:05:00 AM','11/1/2015 1:06:00 AM','11/1/2015 1:07:00 AM','11/1/2015 1:08:00 AM','11/1/2015 1:09:00 AM','11/1/2015 1:10:00 AM','11/1/2015 1:11:00 AM','11/1/2015 1:12:00 AM','11/1/2015 1:13:00 AM','11/1/2015 1:14:00 AM','11/1/2015 1:15:00 AM','11/1/2015 1:16:00 AM','11/1/2015 1:17:00 AM','11/1/2015 1:18:00 AM','11/1/2015 1:19:00 AM','11/1/2015 1:20:00 AM','11/1/2015 1:21:00 AM','11/1/2015 1:22:00 AM','11/1/2015 1:23:00 AM','11/1/2015 1:24:05 AM','11/1/2015 1:25:05 AM','11/1/2015 1:26:05 AM','11/1/2015 1:27:05 AM','11/1/2015 1:28:05 AM','11/1/2015 1:29:10 AM','11/1/2015 1:30:10 AM','11/1/2015 1:31:10 AM','11/1/2015 1:32:10 AM','11/1/2015 1:33:10 AM','11/1/2015 1:34:10 AM','11/1/2015 1:35:10 AM','11/1/2015 1:36:10 AM','11/1/2015 1:37:10 AM','11/1/2015 1:38:10 AM','11/1/2015 1:39:10 AM','11/1/2015 1:40:10 AM','11/1/2015 1:41:10 AM','11/1/2015 1:42:10 AM','11/1/2015 1:43:10 AM','11/1/2015 1:44:10 AM','11/1/2015 1:45:10 AM','11/1/2015 1:46:10 AM','11/1/2015 1:47:10 AM','11/1/2015 1:48:10 AM','11/1/2015 1:49:15 AM','11/1/2015 1:50:15 AM','11/1/2015 1:51:15 AM','11/1/2015 1:52:15 AM','11/1/2015 1:53:15 AM','11/1/2015 1:54:15 AM','11/1/2015 1:55:20 AM','11/1/2015 1:56:20 AM','11/1/2015 1:57:20 AM','11/1/2015 1:58:20 AM','11/1/2015 1:59:20 AM','11/1/2015 2:00:20 AM','11/1/2015 2:01:20 AM')
更新:正如评论所指出的,这可能是与操作系统相关的问题。上述行为最初是在Windows机器上观察到的,我无法在Linux机器上重现上述行为。