rossta / montrose

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

.every(:week, interval: 2) does not interact with on as expected #144

Closed JonPugsley closed 8 months ago

JonPugsley commented 3 years ago

I've been tinkering with this library and like what I see, though I've either found a bug or don't quite understand the options.

Pattern:

Montrose.every(:week, interval: 2).on(["sunday", "monday"]).between(("2021-05-02".to_time)..("2021-05-22".to_time)).events.to_a

Events:

[2021-05-02, 2021-05-10, 2021-05-16]

The matching dates are the sunday of one week, then the monday of the next week, then the sunday of the week after that image

I would expect the dates to be [2021-05-02, 2021-05-03, 2021-05-16, 2021-05-17] image

It seems like the library is running a Monday-Sunday week with no option to change this (though Sunday seems to have a day number of 0, which implies a Sunday-Monday week)

thewatts commented 2 years ago

Hey @JonPugsley - I just tried that same command into my console, and the results were what you mentioned expecting:

Montrose.every(:week, interval: 2).on(["sunday", "monday"]).between(("2021-05-02".to_time)..("2021-05-22".to_time)).events.to_a

image

Are you using the most recent version of the gem?

mikalai-yankouski commented 2 years ago
Screen Shot 2022-04-19 at 15 06 16

@thewatts I have the same behavior

cavi21 commented 1 year ago

Hi @thewatts I also get the same output as @mikalai-yankouski and @JonPugsley ... Screen Shot 2022-10-20 at 12 53 34

the version is the montrose (0.13.0)

rossta commented 8 months ago

Montrose depends on ActiveSupport for Date/Time calculations. For this recurrence, you'll see different results depending on whether the ActiveSupport Date.beginning_of_week setting is set to Sunday or Monday.

@JonPugsley I suspect Monday is set as the beginning of week in the application where you were testing this recurrence. You could test this on the console: Date.beginning_of_week.

You can get the results you are expecting with

Date.beginning_of_week = :sunday

Or in Rails

# config/application.rb

config.beginning_of_week = :sunday

I've added documentation and tests in #164 to further illustrate. Hope that is helpful.