-
Notifications
You must be signed in to change notification settings - Fork 207
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
Refactors quarter()
API to allow for quarter start- and end-dates
#955
Conversation
One thing: I tried running |
FWIW these capabilities come built into the upcoming clock package, where the year-quarter-day calendar is a first class type. library(clock)
library(lubridate)
x <- as.Date("2019-04-25")
yqd1 <- as_year_quarter_day(x)
yqd1
#> <year_quarter_day<January><day>[1]>
#> [1] "2019-Q2-25"
# Get the quarter
quarter(x)
#> [1] 2
get_quarter(yqd1)
#> [1] 2
# Change the fiscal start month and try again
yqd2 <- as_year_quarter_day(x, start = clock_months$april)
yqd2
#> <year_quarter_day<April><day>[1]>
#> [1] "2020-Q1-25"
quarter(x, fiscal_start = 4)
#> [1] 1
get_quarter(yqd2)
#> [1] 1
# Get the year+quarter
quarter(x, type = "quarter_year")
#> [1] 2019.2
paste0(get_year(yqd1), ".", get_quarter(yqd1))
#> [1] "2019.2"
# or, more appropriately:
calendar_narrow(yqd1, "quarter")
#> <year_quarter_day<January><quarter>[1]>
#> [1] "2019-Q2"
# Get the first day of the quarter
quarter(x, type = "date_first")
#> [1] "2019-04-01"
as.Date(set_day(yqd1, 1))
#> [1] "2019-04-01"
# Get the last day of the quarter
quarter(x, type = "date_last")
#> [1] "2019-06-30"
as.Date(set_day(yqd1, "last"))
#> [1] "2019-06-30" Created on 2021-03-03 by the reprex package (v1.0.0) |
@DavisVaughan Neat! Is the idea that |
Not really supersede. Instead we currently are thinking of it as an alternative to lubridate, with lubridate still living on and being a powerful tool for working with date-times. In the far future, bits and pieces of lubridate (like this, for example) might end up relying on clock, but that is still a little uncertain. |
Hey @vspinu, any thoughts on this? Let me know if you want me to tweak anything. |
Sorry for delaying on this. There was an issue with the logical check which could fail for non-logical inputs. Also I don't quite like |
@tomcardoso you might have missed my last message. If you disagree with my amendments please let me know. |
Oh shoot, sorry @vspinu, I did miss this. Makes total sense to me – thanks for talking me through this stuff. Looking forward to putting the new functionality to use! |
Addresses #947. With this, the API now looks like:
The
with_year
parameter is soft-deprecated, but will continue to work for the time being.