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

`floor_date(date, "year")` is off by one in leap years #567

Closed
nacnudus opened this issue Jul 19, 2017 · 5 comments

Comments

@nacnudus
Copy link

commented Jul 19, 2017

library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#> 
#>     date
floor_date(ymd("2016-02-29"), "year")
#> [1] "2016-01-01"
floor_date(ymd("2016-03-01"), "year")
#> [1] "2015-12-31"

# I would expect the equivalent of this
ymd("2016-02-29") - ddays(yday(ymd("2016-02-29")) - 1)
#> [1] "2016-01-01"
ymd("2016-03-31") - ddays(yday(ymd("2016-03-31")) - 1)
#> [1] "2016-01-01"
@hadley

This comment has been minimized.

Copy link
Member

commented Aug 29, 2017

I just discovered this too

@DavisVaughan

This comment has been minimized.

Copy link
Member

commented Sep 25, 2017

+1 to get this fixed. Was planning on using it for period conversion in tibbletime.

@vspinu

This comment has been minimized.

Copy link
Member

commented Sep 26, 2017

Sorry for being slow on this and other issues. My bandwidth for R open source has been close to zero recently. Will have a look later this week.

@DavisVaughan

This comment has been minimized.

Copy link
Member

commented Sep 27, 2017

@vspinu, I'm no expert on lubridate, but I forked it and commenting out this line seems to fix the problem. I'm not sure if that line needs to be there? Just a thought.

All tests (that were passing before the change) still pass.

@vspinu

This comment has been minimized.

Copy link
Member

commented Oct 1, 2017

@DavisVaughan, you are right. I have no idea why that line is there.. It might have had some sense in the earlier drafts of that functionality, but I don't recall anymore.

@vspinu vspinu closed this in 7fc4d92 Oct 1, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.