From 3ad47c4c89619345c4e77793673231bce1c130a7 Mon Sep 17 00:00:00 2001 From: Gabriel Gilder Date: Fri, 28 Mar 2014 15:37:31 -0700 Subject: [PATCH] Make config.utc actually work Fixes #76. --- lib/sidetiq/schedule.rb | 6 ++++-- test/test_clock.rb | 2 +- test/test_schedule.rb | 7 +++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/sidetiq/schedule.rb b/lib/sidetiq/schedule.rb index e934bd5..7665a5a 100644 --- a/lib/sidetiq/schedule.rb +++ b/lib/sidetiq/schedule.rb @@ -9,10 +9,12 @@ module Sidetiq # Public: Start time offset from epoch used for calculating run # times in the Sidetiq schedules. - START_TIME = Sidetiq.config.utc ? Time.utc(2010, 1, 1) : Time.local(2010, 1, 1) + def self.start_time + Sidetiq.config.utc ? Time.utc(2010, 1, 1) : Time.local(2010, 1, 1) + end def initialize # :nodoc: - @schedule = IceCube::Schedule.new(START_TIME) + @schedule = IceCube::Schedule.new(self.class.start_time) end def method_missing(meth, *args, &block) # :nodoc: diff --git a/test/test_clock.rb b/test/test_clock.rb index 77fbe9b..640b14f 100644 --- a/test/test_clock.rb +++ b/test/test_clock.rb @@ -19,7 +19,7 @@ class TestClock < Sidetiq::TestCase def test_backfilling BackfillWorker.jobs.clear Sidetiq.stubs(:workers).returns([BackfillWorker]) - start = Sidetiq::Schedule::START_TIME + start = Sidetiq::Schedule.start_time BackfillWorker.stubs(:last_scheduled_occurrence).returns(start.to_f) clock.stubs(:gettime).returns(start) diff --git a/test/test_schedule.rb b/test/test_schedule.rb index 50a2d3a..f687aed 100644 --- a/test/test_schedule.rb +++ b/test/test_schedule.rb @@ -34,5 +34,12 @@ class TestSchedule < Sidetiq::TestCase sched.set_options(backfill: false) refute sched.backfill? end + + def test_use_utc + Sidetiq.config.utc = true + assert_equal(Time.utc(2010, 01, 01), Sidetiq::Schedule.new.start_time) + ensure + Sidetiq.config.utc = false + end end