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

allow completion of partial dates/datetimes to middle or end of interval #885

Open reikoch opened 4 years ago

reikoch commented 4 years ago

I would like to see an additional option "pointto" to ymd family of functions that regulates how truncation of partial dates works.
ymd("2019", truncated=2, pointto=xy)
should result in

vspinu commented 4 years ago

This is tricky at the moment. But might be much easier once the parser is out of lubridate and dependency on strptime is out. For now you can do this by explicitly calling ceiling_date on those inputs which are shorter. Extra 2 lines of code; not a big deal.

reikoch commented 4 years ago

Interesting idea to work-around with ceiling_date! Just the problem remains to first find out what unit to use - month if only day is missing, year if also month is missing:

Would be great if the future date and datetime parser could help.