tidyverse / lubridate

Make working with dates in R just that little bit easier
https://lubridate.tidyverse.org
GNU General Public License v3.0
724 stars 207 forks source link

month() and otehrs fail on objects from class 'timeDate' #1150

Open GeoBosh opened 7 months ago

GeoBosh commented 7 months ago

A number of functions, such as month() and wday(), are documented to work on objects from class 'timeDate' (from package 'timeDate') but some throw warnings:

lubridate::month(timeDate::timeDate("2023-12-21"))
## [1] 12
## Warning message:
## tz(): Don't know how to compute timezone for object of class timeDate; returning "UTC". 

lubridate::wday(timeDate::timeDate("2023-12-21"))
## [1] 5
## Warning message:
## tz(): Don't know how to compute timezone for object of class timeDate; returning "UTC". 

Also, there is a timeSeries method for tz but it is wrong:

## wrong
lubridate:::tz.timeSeries 
function (x) 
{
    tz(x@FinCenter)  # should be just `x@FinCenter`
}

Both can be fixed by setting:

tz.timeDate <- tz.timeSeries <- function (x) {
    x@FinCenter
}

and registering tz.timeDate (tz.timeSeries is already registered).

tz(as.POSIXlt(1:10, tz = "America/New_York"))
## [1] "America/New_York"

lubridate::tz(timeDate(as.POSIXlt(1:10, tz = "America/New_York"), FinCenter = "America/New_York" ))
## expect after fix: "America/New_York" 

lubridate::tz(timeSeries::timeSeries(1:10, FinCenter = "America/New_York"))
## expect after fix:  "America/New_York"