ice-cube-ruby / ice_cube

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

Inconsistent daily schedule with interval behaviour between version 0.16.3 and 0.16.4 #514

Open unrooty-infinum opened 3 years ago

unrooty-infinum commented 3 years ago

Hello! First of all thanks for the gem, you did a great job!

I'm facing an issue with daily schedule with interval after ice_cube update from version 0.16.3 to version 0.16.4.

According the following reproducion scripts you can see that version 0.16.3 output differs from version 0.16.4 output.

Is it expected behaviour? And which version output is correct?

Environment

Ruby: 3.0.2p107 (2021-07-07 revision 0db68f0233) [arm64-darwin20] OS: MacOS Big Sur 11.6

Version 0.16.3 behaviour reproducion script

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'ice_cube', '0.16.3'
end

require 'ice_cube'

interval = 4

rule = IceCube::Rule.daily(interval).hour_of_day(9).minute_of_hour(0).second_of_minute(0)

start_time = Time.new(2021, 3, 28, 10, 0, 0, 'UTC') # 2021-03-28 10:00:00 UTC
end_time = Time.new(2021, 4, 7, 23, 59, 59, 'UTC') # 2021-04-07 23:59:59 UTC

schedule = IceCube::Schedule.new(start_time) { |s| s.add_recurrence_rule(rule) }

schedule.occurrences(end_time)

# Output
# 2021-03-29 09:00:00 UTC
# 2021-04-02 09:00:00 UTC
# 2021-04-06 09:00:00 UTC

Version 0.16.4 behaviour reproducion script


require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'ice_cube', '0.16.4'
end

require 'ice_cube'

interval = 4

rule = IceCube::Rule.daily(interval).hour_of_day(9).minute_of_hour(0).second_of_minute(0)

start_time = Time.new(2021, 3, 28, 10, 0, 0, 'UTC') # 2021-03-28 10:00:00 UTC
end_time = Time.new(2021, 4, 7, 23, 59, 59, 'UTC') # 2021-04-07 23:59:59 UTC

schedule = IceCube::Schedule.new(start_time) { |s| s.add_recurrence_rule(rule) }

schedule.occurrences(end_time)

# Output
# 2021-04-01 09:00:00 UTC
# 2021-04-05 09:00:00 UTC
pacso commented 3 years ago

Hey, thanks for getting in touch.

Funnily enough, you've picked the day that clocks change. There was a bug previously that meant that schedules around the clock-change days were incorrectly calculated. This was fixed in the latest release.

Since your schedule starts after the occurrence rule, you don't see the event from the 28th March, but you do see them from the 1st April onwards. The previous behaviour of one existing on the 29th was a bug which is now fixed. The behaviour you see in 0.16.4 is what I would expect.

If I've misunderstood something and you're expecting some different behaviour, then please let me know and we'll investigate further.

pacso commented 2 years ago

@unrooty-infinum - after chatting to @seejohnrun about it, we agree that this behaviour isn't right.

Interestingly, if you're not using the daily(4) interval, it starts the first occurrence on the right date/time. Will open a PR to resolve it.

unrooty-infinum commented 2 years ago

@pacso sorry, missed your first reply. I guess that 0.16.3 behaviour is correct because my customer would open a task(bug) in other case, hahaha :)

Anyway thanks for the reply! Please let me know if I can help to resolve this issue.