ice_cube icon indicating copy to clipboard operation
ice_cube copied to clipboard

hour_of_day not working properly with daily rule

Open rbarrera87 opened this issue 8 years ago • 1 comments

I found that when I create an schedule with daily and hour_of_day rules, next_occurrence is not using the daily rule, only hour_of_day. Take the following example:

current_time = Time.current
# => Mon, 02 Apr 2018 13:38:25 PDT -07:00
schedule = IceCube::Schedule.new(current_time)
rule = IceCube::Rule.daily(2).hour_of_day(17)
schedule.add_recurrence_rule(rule)
schedule.next_occurrence
# => Mon, 02 Apr 2018 17:39:40 PDT -07:00
# I think next_occurrence should be 2 days later ( Mon, 04 Apr 2018 17:39:40 PDT -07:00)
schedule.to_s
#=> "Every 2 days on the 17th hour of the day"

If I just add the daily rule it work as expected

schedule = IceCube::Schedule.new(current_time)
rule = IceCube::Rule.daily(2)
schedule.add_recurrence_rule(rule)
schedule.next_occurrence
# => Wed, 04 Apr 2018 13:39:40 PDT -07:00

Or perhaps I am missing something 🤔 What I do want to have here is a schedule of Every 2 days meaning after 2 days on the 17th hour of the day.

Thank you!

rbarrera87 avatar Apr 02 '18 20:04 rbarrera87

Update: I realized that is happening only when I have a timezone set to something different to UTC

Time.zone
# => #<ActiveSupport::TimeZone:0x00000000073d5b10 @name="Pacific Time (US & Canada)", @utc_offset=nil, @tzinfo=#<TZInfo::DataTimezone: America/Los_Angeles>>
Time.zone = 'UTC'
# => "UTC"
Time.zone
# => #<ActiveSupport::TimeZone:0x000000000b11dce8 @name="UTC", @utc_offset=nil, @tzinfo=#<TZInfo::DataTimezone: Etc/UTC>>
t = Time.current
# => Mon, 02 Apr 2018 20:55:32 UTC +00:00
schedule = IceCube::Schedule.new(t)
rule = IceCube::Rule.daily(2).hour_of_day(17)
schedule.add_recurrence_rule(rule)
schedule.next_occurrence
# => Wed, 04 Apr 2018 17:55:32 UTC +00:00

rbarrera87 avatar Apr 02 '18 21:04 rbarrera87