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

add_period_to_date/add_months returns NA for some dates/periods #633

Closed
mwmclean opened this issue Feb 5, 2018 · 1 comment
Closed

add_period_to_date/add_months returns NA for some dates/periods #633

mwmclean opened this issue Feb 5, 2018 · 1 comment
Labels
bug

Comments

@mwmclean
Copy link

@mwmclean mwmclean commented Feb 5, 2018

library(lubridate)
start <- c("2016-04-29 12:00:00 GMT", "2013-10-31 12:00:00 GMT", "2012-05-31 12:00:00 GMT", "2010-06-29 12:00:00 GMT",
           "2014-12-31 12:00:00 GMT", "2015-08-31 12:00:00 GMT", "2013-03-29 12:00:00 GMT", "2014-07-31 12:00:00 GMT")
end <- c("2017-03-25", "2014-03-16", "2012-12-15", "2011-03-25", "2015-10-16" ,"2016-03-16", "2014-03-28" ,"2015-07-22")
mt <- as.POSIXlt(start)
int <- interval(start, end)
id <- int %/% months(1)

int %% months(1)
## [1] NA--NA NA--NA NA--NA NA--NA NA--NA NA--NA NA--NA NA--NA
mt + months(id)
## [1] NA NA NA NA NA NA NA NA
lubridate:::add_months(mt, id)
## [1] NA NA NA NA NA NA NA NA
@mwmclean mwmclean closed this Feb 6, 2018
@mwmclean mwmclean changed the title add_period_to_date/add_months fails for some dates/periods add_period_to_date/add_months returns NA for some dates/periods Feb 7, 2018
@mwmclean mwmclean reopened this Feb 7, 2018
@vspinu vspinu added the bug label Feb 22, 2018
@vspinu vspinu closed this in fa5520f Apr 10, 2018
@vspinu
Copy link
Member

@vspinu vspinu commented Apr 10, 2018

I am fixing %% issue as I think it would make more sense to use m+ arithmetic there but others behave as expected. See the docs for %m+%.

With the github version you should see:

> int %% months(1)
[1] 2017-02-28 12:00:00 CET--2017-03-25 CET  
[2] 2014-02-28 12:00:00 CET--2014-03-16 CET  
[3] 2012-11-30 12:00:00 CET--2012-12-15 CET  
[4] 2011-02-28 12:00:00 CET--2011-03-25 CET  
[5] 2015-09-30 12:00:00 CEST--2015-10-16 CEST
[6] 2016-02-29 12:00:00 CET--2016-03-16 CET  
[7] 2014-02-28 12:00:00 CET--2014-03-28 CET  
[8] 2015-06-30 12:00:00 CEST--2015-07-22 CEST
> mt + months(id)
[1] NA NA NA NA NA NA NA NA
> mt %m+% months(id)
[1] "2017-02-28 12:00:00 UTC" "2014-02-28 12:00:00 UTC"
[3] "2012-11-30 12:00:00 UTC" "2011-02-28 12:00:00 UTC"
[5] "2015-09-30 12:00:00 UTC" "2016-02-29 12:00:00 UTC"
[7] "2014-02-28 12:00:00 UTC" "2015-06-30 12:00:00 UTC"
> add_with_rollback(mt, months(id))
[1] "2017-02-28 12:00:00 UTC" "2014-02-28 12:00:00 UTC"
[3] "2012-11-30 12:00:00 UTC" "2011-02-28 12:00:00 UTC"
[5] "2015-09-30 12:00:00 UTC" "2016-02-29 12:00:00 UTC"
[7] "2014-02-28 12:00:00 UTC" "2015-06-30 12:00:00 UTC"
> add_with_rollback(mt, months(id), T, F)
[1] "2017-03-01 UTC" "2014-03-01 UTC" "2012-12-01 UTC" "2011-03-01 UTC"
[5] "2015-10-01 UTC" "2016-03-01 UTC" "2014-03-01 UTC" "2015-07-01 UTC"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants