rossta / montrose

Recurring events library for Ruby. Enumerable recurrence objects and convenient chainable interface.

Home Page:https://rossta.net/montrose/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support inquiries other than .include?

martinstreicher opened this issue · comments

I am posting this to collect thoughts and perhaps learn of approaches using the current code.

I see that .include? is a way to determine if a timestamp (instance of Time) is included in a schedule. That's useful, but it's making very fine-grained comparisons to yield a match.

I would like to have the following methods:

  • Schedule#occuring_on?(Date(yyyy, mm, dd): This method would ignore the timestamp and compare only by date.

    For example, schedule.occurring_on?(Date.new(2019, 9, 1)) is true if Sept 1, 2019 is among the dates in the schedule. (I know I can implement this by converting an occurrence to a Date and then looking for matches using a variety of techniques (date ranges, set intersection, etc.) It would be nice to have this as a convenience: the occurrences would be converted to dates and the argument would be converted to a Date. It might be nice to have a corollary occurring_on? on the recurrence model itself.

  • To have parity with occurring_on?, offer occurring_at? on Schedule and Montrose to answer if a given time stamp is captured by the schedule or recurrence rule, respectively.

  • .after(Date/Time) yields the next occurrence after the given date or timestamp. .before would do the same thing before the point in time.

I am sure there are other conveniences for comparing, such as whether a calendar includes any of the times, all of the times, none of the the times.

@martinstreicher Thanks for the suggestions. Feel free to start a PR if you're able/interested in adding these features.

I am working with this code on a project, so I can likely put up a PR shortly.

Closing for now. Feel free to open if you're still actively working on this.