Final Edit: known bug: https://github.com/hadley/lubridate/issues/188
I found the bug, as it were: Apparently the POSIXct
-class object will allow you to modify its seconds
portion, but there's no "carry" function, so if you force the total seconds to exceed 59, it gives up.
Rgames> as.POSIXct("2010-10-17 07:59:30")->dfoo
Rgames> dfoo
[1] "2010-10-17 07:59:30 EDT"
Rgames> second(dfoo)
[1] 30
Rgames> second(dfoo)<-second(dfoo)+10
Rgames> dfoo
[1] "2010-10-17 07:59:40 EDT"
Rgames> second(dfoo)<-second(dfoo)+seconds(10)
Rgames> dfoo
[1] "2010-10-17 07:59:50 EDT"
Rgames> second(dfoo)<-second(dfoo)+seconds(10)
Rgames> dfoo
[1] NA
What the intended use of the lubridate::seconds
and second
functions are, I dunno, but clearly this ain't the way to go :-( .
EDIT: I kept playing, with dfoo
as above and dbar <- as.POSIXct("2010-10-17 07:59:30",tz='GMT')
. I could add arbitrary seconds to dbar
w/o problem. Further, I used with_tz
to switch the time zones for both dfoo
and dbar
, and regardless of the zone assigned, could successfully add arbitrary seconds.
This leads me to wonder just what the [redacted] as.POSIXct
does with the default tz=''
argument!
EDIT 2: hey, look:
Rgames> as.POSIXct("2010-10-17 07:59:30")->dfoo
Rgames> dfoo + seconds(55)
[1] "2010-10-17 08:00:25 EDT"
Rgames> dfoo + seconds(30)
[1] NA
Rgames> dfoo + seconds(31)
[1] "2010-10-17 08:00:01 EDT"
Rgames> dfoo + seconds(29)
[1] "2010-10-17 07:59:59 EDT"