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

Adding "quarter" option to floor/ceiling_date #303

Merged
merged 1 commit into from
Feb 10, 2015
Merged

Adding "quarter" option to floor/ceiling_date #303

merged 1 commit into from
Feb 10, 2015

Conversation

jonboiser
Copy link
Contributor

In reference to Issue 239.

switch(unit,
minute = minute(y) <- minute(y) + 1,
hour = hour(y) <- hour(y) + 1,
day = yday(y) <- yday(y) + 1,
week = week(y) <- week(y) + 1,
month = month(y) <- month(y) + 1,
year = year(y) <- year(y) + 1
year = year(y) <- year(y) + 1,
quarter = { month(y) <- month(y) + 3; y <- y - ddays(1) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to subtract ddays(1)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue reporter wanted ceiling to return the last day of the quarter. This line adds three months to the first day of the quarter, then subtracts one (to handle months with 28/30/31 days), instead of adding two months, and having to figure out how long a month is to get the last day.

Is there a function in lubridate that gives the number of days like "number of days in february on a non-leap year = 28"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces an exception for quarter and we don't want that. OP can substract 1 day himself if so desired.

@jonboiser
Copy link
Contributor Author

Took awhile, but got the PR all cleaned up with a minimal diff.

vspinu added a commit that referenced this pull request Feb 10, 2015
Adding "quarter" option to floor/ceiling_date
@vspinu vspinu merged commit 5ecc319 into tidyverse:master Feb 10, 2015
@vspinu
Copy link
Member

vspinu commented Feb 10, 2015

👍 Thanks.

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

Successfully merging this pull request may close these issues.

None yet

2 participants