tidyverse / lubridate

Make working with dates in R just that little bit easier
https://lubridate.tidyverse.org
GNU General Public License v3.0
724 stars 207 forks source link

Improvement Suggestion: Trimester Option with semester() #1134

Open dpranjic-r opened 10 months ago

dpranjic-r commented 10 months ago

Currently, the semester() accessor function from lubridate does not have an option for more than two semesters per year. It would be helpful if the function offered the option to set the number of semesters and start dates, or at the very least offer a trimester option, with the spring, summer, and fall semesters starting on January 1, May 1, and August 1 (typical start dates at large state universities). Thank you for your time and consideration.

vspinu commented 10 months ago

It should be a new function, multimester or varimester, something that would accept a range of months, in your example c(1, 5, 8).

Right now you can floor_date to a date vector (unit argument). So you can construct a vector of 1st of Januarys, Mays, and Augusts and round to those. Something like this:

> y <- today() + months(1:20)
> month(
+   floor_date(
+     update(y, year = 2000),
+     ISOdate(year = 2000, month = c(1, 5, 8), day = 1)
+   ))
## [1] 8 8 8 1 1 1 1 5 5 5 8 8 8 8 8 1 1 1 1 5

I would consider a PR for the implementation of varimester