data.table has the IDate class:
IDate is a date class derived from Date. It has the same internal representation as the Date class, except the storage mode is integer.
From ?lubridate::year:
Date-time must be a [...] Date [...] or any other object convertible to POSIXlt.
Create IDate object, check class, and coerce to POSIXlt:
d = data.table::as.IDate("2022-08-28")
class(d)
# [1] "IDate" "Date"
class(as.POSIXlt(d))
# [1] "POSIXlt" "POSIXt"
Thus, an IDate object, having also class Date and being coercible to POSIXlt, seems to fulfil the requirements of the input object of lubridate::year. Indeed, it is possible to use lubridate::year to get the year component of an IDate object. However setting the year fails. Wouldn't we expect year<- to work as well?
# get year works
lubridate::year(d)
# [1] 2022
# set year errors
lubridate::year(d) <- 2021
# Error: Incompatible classes: <IDate> + <Period>
data.tablehas theIDateclass:From
?lubridate::year:Create
IDateobject, check class, and coerce toPOSIXlt:Thus, an
IDateobject, having also classDateand being coercible toPOSIXlt, seems to fulfil the requirements of the input object oflubridate::year. Indeed, it is possible to uselubridate::yearto get the year component of anIDateobject. However setting the year fails. Wouldn't we expectyear<-to work as well?