Skip to content
New issue

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

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

Already on GitHub? # 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
Closed

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

nacnudus opened this issue Jul 19, 2017 · 5 comments

Comments

@nacnudus
Copy link

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
Copy link
Member

hadley commented Aug 29, 2017

I just discovered this too

@DavisVaughan
Copy link
Member

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

@vspinu
Copy link
Member

vspinu 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
Copy link
Member

@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
Copy link
Member

vspinu 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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants