rossta / montrose

Recurring events library for Ruby. Enumerable recurrence objects and convenient chainable interface.
https://rossta.net/montrose/
MIT License
843 stars 53 forks source link

Interval should be able to provide reference point besides "starts" #82

Closed djvs closed 7 years ago

djvs commented 7 years ago

Let's say I want a range with every 3 days. I want to slice that interval up between Feb 1 and Mar 3. But I want it to be every 3 days starting on Feb 2, counting before or after:

> Montrose.r(interval: 3, between: Date.parse("Feb 1 2017")..Date.parse("Mar 3 2017"), starts: Date.parse("Feb 2 2017"), every: :day).to_a
> ## OR ALSO...
> Montrose.r(interval: 3, starts: Date.parse("Jan 31 2017"), between: Date.parse("Feb 1 2017")..Date.parse("Mar 3 2017"), every: :day).to_a                    
=> [2017-02-01 00:00:00 -0500,
 2017-02-04 00:00:00 -0500,
 2017-02-07 00:00:00 -0500,
 2017-02-10 00:00:00 -0500,
 2017-02-13 00:00:00 -0500,
 2017-02-16 00:00:00 -0500,
 2017-02-19 00:00:00 -0500,
 2017-02-22 00:00:00 -0500,
 2017-02-25 00:00:00 -0500,
 2017-02-28 00:00:00 -0500]

I literally installed the library for this use case and then found out it wouldn't work. Or will it?

rossta commented 7 years ago

So I understand your use case more clearly, what results are you expecting to get?

djvs commented 7 years ago

That the range is "affixed" on a reference date, but happens within a range whose boundaries do not include any of its members. E.g., every tenth day, next Wednesday being included, between next Monday and October 10th.

On Mar 10, 2017 8:25 AM, "Ross Kaffenberger" notifications@github.com wrote:

So I understand your use case more clearly, what results are you expecting to get?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rossta/montrose/issues/82#issuecomment-285668237, or mute the thread https://github.com/notifications/unsubscribe-auth/AC0UZ3NwEyVebDXudAr-iGoxHwYYems-ks5rkU9bgaJpZM4MY7MM .

rossta commented 7 years ago

Got it. So far :between has been considered shorthand for :starts and :until. The behavior you're looking for is not currently supported but it could be; sounds like a good feature request.

djvs commented 7 years ago

Well I'll share with you the work around that I implemented. What I did was take the reference date, for inclusion in the interval and its two boundaries, and for each of those, reason out the first or last included date in the interval, and then just count forward or backward from there for the members. Just guessing re: the Montrose implementation, it'd probably be a matter of finding the first, if any, member included in the interval, and then substituting it for the start parameter?

On Mar 10, 2017 9:09 AM, "Ross Kaffenberger" notifications@github.com wrote:

Got it. So far :between has been considered shorthand for :starts and :until. The behavior you're looking for is not currently supported but it could be; sounds like a good feature request.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rossta/montrose/issues/82#issuecomment-285677718, or mute the thread https://github.com/notifications/unsubscribe-auth/AC0UZ3Ul_RCa8r1ty6aMx7dZKwvTKp1kks5rkVmLgaJpZM4MY7MM .

rossta commented 7 years ago

Try the latest changes on master when you get a chance.