ice_cube icon indicating copy to clipboard operation
ice_cube copied to clipboard

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

Open TruffeCendree opened this issue 3 years ago • 2 comments

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.

TruffeCendree avatar May 14 '21 09:05 TruffeCendree

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

zernie avatar May 27 '21 12:05 zernie

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.

TruffeCendree avatar May 27 '21 12:05 TruffeCendree