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

Periods with Inf values causes an error #1133

Closed avsdev-cw closed 11 months ago

avsdev-cw commented 11 months ago

Whilst uncommon, it believe it should be possible to have a period with an infinite value (which when applied to a date with an operation, should result in an infinite date). Currently there is some code in periods.r which prevents this from being a possibility:

https://github.com/tidyverse/lubridate/blob/cae67eaee701f5041425968fc2a838e9fa25ed19/R/periods.r#L29C1-L32C4

  if (sum(values - trunc(values))) {
    msg <- "periods must have integer values"
    errors <- c(errors, msg)
  }

Reprex:

lubridate::today() + Inf
#> [1] "Inf"
lubridate::today() + lubridate::days(Inf)
#> Error in if (sum(values - trunc(values))) {: argument is not interpretable as logical

I should note, the reason I am doing this is in a dplyr::mutate I need to add a number of days to a date to determine a deadline: Inf is used to specify that there is no deadline, whereas NA is used to specify that no deadline has been specified yet

vspinu commented 11 months ago

Thanks for reporting! I have fixed the error but the actual computation has to be fixed in https://github.com/vspinu/timechange/issues/29 For now you will get the NA instead of the Inf date.