ice-cube-ruby / ice_cube

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

IceCube::Schedule#occurrences_between miss occurrences strictly included in range #497

Open TruffeCendree opened 3 years ago

TruffeCendree commented 3 years ago

I have a reccurring rule, which should occur on 2021-08-16 08:00:00 +0200. But calling schedule.occurrences_between with a range strictly including the occurrence returns [].

The following snippet reproduces the issue on version 0.16.3.

serialized = {"rrules"=>
  [{"until"=>{"time"=>"2021-09-30T21:59:00.000Z", "zone"=>"Europe/Paris"},
    "interval"=>2,
    "rule_type"=>"IceCube::WeeklyRule",
    "week_start"=>1,
    "validations"=>{"day"=>[1], "hour_of_day"=>[8], "minute_of_hour"=>[0]}}],
 "rtimes"=>[],
 "extimes"=>[],
 "end_time"=>{"time"=>"2021-06-07T08:45:00.000Z", "zone"=>"Europe/Paris"},
 "start_time"=>{"time"=>"2021-06-07T06:00:00.000Z", "zone"=>"Europe/Paris"}}

schedule = IceCube::Schedule.from_hash(serialized)

# returns [], expected to return ["2021-08-16 08:00:00 +0200 - 2021-08-16 10:45:00 +0200"]
schedule.occurrences_between("2021-08-16 00:00:00 +0200".to_time, "2021-08-17 00:00:00 +0200".to_time)

# returns [], expected to return ["2021-08-16 08:00:00 +0200 - 2021-08-16 10:45:00 +0200"]
schedule.occurrences_between("2021-08-16 00:00:00 +0200".to_time - 1.week, "2021-08-17 00:00:00 +0200".to_time)

# returns ["2021-08-16 08:00:00 +0200 - 2021-08-16 10:45:00 +0200"]
# expected to return ["2021-08-02 08:00:00 +0200 - 2021-08-02 10:45:00 +0200", "2021-08-16 08:00:00 +0200 - 2021-08-16 10:45:00 +0200"]
schedule.occurrences_between("2021-08-16 00:00:00 +0200".to_time - 2.weeks, "2021-08-17 00:00:00 +0200".to_time)

Thanks.

zernie commented 3 years ago

Damn, this issue cost me half a day. I have to substract 1s from time_end to make it work

TruffeCendree commented 3 years ago

In our case, we got it working by removing hour_of_day and minute_of_hour from validations. start_time must be aligned with hours and minutes we want.