-
Notifications
You must be signed in to change notification settings - Fork 210
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
Problem to add a year when date is a 29 Feb #284
Comments
What version is this? I cannot reproduce with the Dev version.
|
I have update R to version 3.1.2 and reinstalled the dev version with I still obtain:
The bug occurs only if the first date is a 29 Feb and if |
Ok, the problem is due to the fact that in this specific case, on line 30 of ymd('1992-2-29')+period(1,"year") whose result is equal to |
In the same way, we have: > x <- ymd('1992-2-29')
> year(x)
[1] 1992
> year(x)<-1993
> x
[1] NA I have changed the title of the issue accordingly |
The issue is the same when adding months if the targeted month doesn't have the "same day" available. Example: > ymd('2012-03-31')+period(1,"months")
[1] NA |
Ok. I see. This is why I haven't spotted it the first time. Will investigate. |
Guys, this is still happening nowadays, is there a way to cirvumvent this problem? |
What are you trying to do exactly ? initial problem is ok library(lubridate)
as.period(interval(ymd('1992-02-29'),ymd('2013-12-05')), units = "year")
#> [1] "21y 9m 6d 0H 0M 0S"
as.period(interval(ymd('1992-02-29'),ymd('2013-12-05')))
#> [1] "21y 9m 6d 0H 0M 0S" and about adding months to some date, this is correctly working and explained in Arithmetic with date times. # 31 of April does not exists, thus NA
ymd('2012-03-31') + months(1)
#> [1] NA
#use %m+% to have the last day of the new month
ymd('2012-03-31') %m+% months(1)
#> [1] "2012-04-30"
ymd('2012-02-29') %m+% months(1)
#> [1] "2012-03-29"
# same with years
ymd('2012-03-31') + years(1)
#> [1] "2013-03-31"
ymd('2012-02-29') %m+% years(1)
#> [1] "2013-02-28" Created on 2018-04-27 by the reprex package (v0.2.0). |
is working well. But
creates the following error:
According to RStudio debugger, the problem comes from line 49 in
ops-division.r
The text was updated successfully, but these errors were encountered: