I find it a little strange that if you add an NA, or initialize with NA, that it doesn't set all of the slots to NA. I feel like this implies that there are multiple "types" of missing Period objects. It might help internal consistency if NA propagated to all slots. This would formalize a missing Period object as one where all slots are NA
library(lubridate)
days(NA_real_)
#> [1] NA
str(days(NA_real_))
#> Formal class 'Period' [package "lubridate"] with 6 slots
#> ..@ .Data : num NA
#> ..@ year : num 0
#> ..@ month : num 0
#> ..@ day : num NA
#> ..@ hour : num 0
#> ..@ minute: num 0
days(NA_real_) + years(1)
#> [1] NA
days(1) + years(NA_real_)
#> [1] NA
str(days(NA_real_) + years(1))
#> Formal class 'Period' [package "lubridate"] with 6 slots
#> ..@ .Data : num NA
#> ..@ year : num 1
#> ..@ month : num 0
#> ..@ day : num NA
#> ..@ hour : num 0
#> ..@ minute: num 0
str(days(1) + years(NA_real_))
#> Formal class 'Period' [package "lubridate"] with 6 slots
#> ..@ .Data : num NA
#> ..@ year : num NA
#> ..@ month : num 0
#> ..@ day : num 1
#> ..@ hour : num 0
#> ..@ minute: num 0
This is what I expect internally:
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#>
#> date
period()[NA_real_]
#> [1] NA
str(period()[NA_real_])
#> Formal class 'Period' [package "lubridate"] with 6 slots
#> ..@ .Data : num NA
#> ..@ year : num NA
#> ..@ month : num NA
#> ..@ day : num NA
#> ..@ hour : num NA
#> ..@ minute: num NA
I find it a little strange that if you add an
NA, or initialize withNA, that it doesn't set all of the slots toNA. I feel like this implies that there are multiple "types" of missing Period objects. It might help internal consistency ifNApropagated to all slots. This would formalize a missing Period object as one where all slots areNAThis is what I expect internally: