Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Periods with Inf values causes an error #1133

Closed
avsdev-cw opened this issue Sep 19, 2023 · 1 comment
Closed

Periods with Inf values causes an error #1133

avsdev-cw opened this issue Sep 19, 2023 · 1 comment

Comments

@avsdev-cw
Copy link

avsdev-cw commented Sep 19, 2023

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 vspinu closed this as completed in f1b7b2f Sep 22, 2023
@vspinu
Copy link
Member

vspinu commented Sep 22, 2023

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

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jan 14, 2024
Version 1.9.3
=============

### NEW FEATURES

* [#682](tidyverse/lubridate#682 (comment))
  Add type="year_start/end" argument to `quarter()` which produces
  a complete description of the quarter.

### BUG FIXES

* [#1109](tidyverse/lubridate#1109)
  Fix recycling of the year slot in `as.period(unit = "month")` with Periods and Intervals.
* [#1133](tidyverse/lubridate#1133)
  Don't error on addition on infinite periods.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants