ice-cube-ruby / ice_cube

Ruby Date Recurrence Library - Allows easy creation of recurrence rules and fast querying
MIT License
2.41k stars 358 forks source link

Option to default to prior friday or following monday when "business weekday only" occurrences fall on a weekend #338

Closed tnypxl closed 7 years ago

tnypxl commented 8 years ago

This is a bit of an edge case and I'm not sure how to account for it given ice_cube's current state.

schedule = IceCube::Schedule.new(t0 = Time.local(2016, 5, 1))
schedule.add_recurrence_rule IceCube::Rule.monthly.day_of_month(15, -1).day(:monday, :tuesday, :wednesday, :thursday, :friday)
schedule.first(2).each { |occurrence| p occurrence.strftime('%A') }

The output:

"Tuesday"
"Wednesday"
 => [2016-05-31 00:00:00 -0500, 2016-06-15 00:00:00 -0500] 

The current behavior skips any occurrence that falls on a weekend. This is expected. But would it be valuable to allow fallback occurrence rules? Maybe I would pass an existing occurrence to a fallback rule and add occurrences accordingly...

Thoughts?

avit commented 7 years ago

Yes this is an interesting scenario. I think this would be covered using the BYSETPOS option being proposed in #289 and #349. I'll try and investigate this further when I have time but do let us know if you have any success trying it with that pull request.

Closing as a duplicate.

tnypxl commented 7 years ago

Thanks @avit!