jameslairdsmith / gs

A grammar of recurring calendar events.
https://jameslairdsmith.github.io/gs/
Other
14 stars 0 forks source link

Rolling dates forwards or backwards. #6

Open jameslairdsmith opened 5 years ago

jameslairdsmith commented 5 years ago

New set of functions allowing users to take a schedule as input and return the same schedule, but with the dates rolled either forward or backward to other dates. Syntax would be something like:

roll_forward(schedule, to_following = on_weekday(), .p = on_weekend())

roll_backward(schedule, to_previous = on_weekday(), .p = on_weekend()) 

Where .p is a predicate indicating there are some dates that should not be rolled.

There could also be a roll_closest() function, which would check one direction first and then the other. The function would start with one or the other depending on the user's input.

jameslairdsmith commented 5 years ago

There should also be a way to do this in fixed increments. Either by a new function like roll_forward_by() or by having an argument to the above functions like by =. This argument or function would take a lubridate duration function like:

roll_forward(schedule, by = dweeks(2))