diff --git a/lib/protokoll/counter.rb b/lib/protokoll/counter.rb index f87d7b2..82a0872 100644 --- a/lib/protokoll/counter.rb +++ b/lib/protokoll/counter.rb @@ -29,7 +29,7 @@ def self.build_attrs(object, options) end def self.outdated?(record, options) - Time.now.utc.strftime(update_event(options)).to_i > record.updated_at.utc.strftime(update_event(options)).to_i + Time.zone.now.strftime(update_event(options)).to_i > record.updated_at.strftime(update_event(options)).to_i end def self.update_event(options) diff --git a/test/protokoll_test.rb b/test/protokoll_test.rb index 858674d..bc6bb4a 100644 --- a/test/protokoll_test.rb +++ b/test/protokoll_test.rb @@ -49,6 +49,40 @@ class Protocol < ActiveRecord::Base assert_equal "20110900002", protocol2.number end + test "timezone should not be a problem" do + class Protocol < ActiveRecord::Base + protokoll :number, pattern: "%y%m%d##" + end + + Time.zone = 'America/New_York' + time = Time.local(2011, 9, 25, 9, 0, 0) + Timecop.travel(time) + protocol1 = Protocol.create + + time = Time.local(2011, 9, 25, 22, 0, 0) + Timecop.travel(time) + protocol2 = Protocol.create + + assert_not_equal protocol1.number, protocol2.number + end + + test "timezone should not be a problem when the time is next day" do + class Protocol < ActiveRecord::Base + protokoll :number, pattern: "%y%m%d##" + end + + Time.zone = 'America/New_York' + time = Time.local(2011, 9, 25, 9, 0, 0) + Timecop.travel(time) + protocol1 = Protocol.create + + time = Time.local(2011, 9, 26, 02, 0, 0) + Timecop.travel(time) + protocol2 = Protocol.create + + assert_not_equal protocol1.number, protocol2.number + end + test "should get 201100002 for second save (format number %Y#####)" do class Protocol < ActiveRecord::Base protokoll :number, :pattern => "%Y#####"