POSIXct times around DST?

I want to subtract 1 day from the POSIX date and end up in DST.

For example, when I add a day:

> as.POSIXct('2009-03-08 23:00:00.000') + 86400
[1] "2009-03-09 23:00:00 EDT"

But when I go, he biases:

> as.POSIXct('2009-03-08 23:00:00.000') - 86400
[1] "2009-03-07 22:00:00 EST"

What is the best way to deal with absolute time differences regarding DST? I usually do this by converting times to strings and processing them separately so that DST is not applied.

+3
source share
5 answers

, , , 24 . 24 (86400 ) 2009-03-08 23:00:00 EDT 2009-03-07 22:00:00 EST. R, POSIX, . POSIXct, day 1, POSIXct POSIXlt ( , , , 1 31 ), .

+2

UTC - UTC . ( )

+1

, hobbs! , POSIXlt:

> a <- as.POSIXct('2009-03-08 23:00:00.000')
> as.POSIXlt(a)
[1] "2009-03-08 23:00:00 EDT"
> a <- as.POSIXlt(a)
> a$mday <- a$mday -1
> a
[1] "2009-03-07 23:00:00 EDT"
+1

, trunc, :

> trunc(Sys.time(), "day") + 86400
[1] "2009-09-13 PDT"
> trunc(Sys.time(), "day") - 86400
[1] "2009-09-11 PDT"
0

lubridate , , . :

, . , , (DST).

, . , .

0

Source: https://habr.com/ru/post/1717178/


All Articles