Is there a way to assign DST transitions automatically in lubridate?

只愿长相守 提交于 2019-12-07 00:49:30

This isn't possible. There's no way to know with certainty that "11/4/2012 1:04:28 AM" is PST and not actually an observation between "11/4/2012 12:51:20 AM" and "11/4/2012 1:13:08 AM" PDT.

If you're certain the observations are ordered in the file, you could convert them to POSIXt and take the diff of the vector. Any negative values will be DST changes. You may miss some, however, if the time between observations across a DST change is greater than 1 hour.

Lines <- "11/4/2012 12:51:20 AM
11/4/2012 01:13:08 AM
11/4/2012 01:24:58 AM
11/4/2012 01:40:28 AM
11/4/2012 01:48:08 AM
11/4/2012 01:54:08 AM
11/4/2012 01:56:58 AM
11/4/2012 01:04:28 AM
11/4/2012 01:05:48 AM
11/4/2012 01:07:18 AM
11/4/2012 01:15:00 AM
11/4/2012 01:39:08 AM
11/4/2012 02:05:38 AM"

x <- scan(con <- textConnection(Lines), what="", sep="\n")
close(con)
diff(strptime(x, format="%m/%d/%Y %I:%M:%S %p"))
# Time differences in mins
#  [1]  21.800000  11.833333  15.500000   7.666667   6.000000   2.833333
#  [7] -52.500000   1.333333   1.500000   7.700000  24.133333  86.500000
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!