Search code examples
rlubridate

Lubridate can't round a Period object


I'm trying to round a lubridate Period object to the nearest minute.

library(lubridate)
round_date(as.period("2d 20H 22M 9.57S"))

Gives

Error in as.POSIXct.numeric(x) : 'origin' must be supplied

So round_date is converting my period to a POSIXct, but why? Is it possible to round periods in lubridate without converting them to another format? Seems like I'm missing something simple.

Thanks!


Solution

  • Since this issue was opened, it is now possible to round a lubridate Period as shown in this thread. Here is the example in your case :

    library("lubridate")  
    round(as.period("2d 20H 22M 9.57S"))  
    [1] "2d 20H 22M 10S"