Permalink
Browse files

standardize on UTC but add the ability to use Time.zone.now if present

  • Loading branch information...
1 parent c5e42bd commit b0a27b4c5bbd7a51701ecfd77361f6e7714c7719 Sven Fuchs committed Dec 1, 2011
Showing with 6 additions and 3 deletions.
  1. +5 −1 lib/simple_states/event.rb
  2. +0 −2 lib/simple_states/states.rb
  3. +1 −0 test/states_test.rb
@@ -59,7 +59,7 @@ def set_state(object)
if state = target_state(object)
object.past_states << object.state if object.state
object.state = state.to_sym
- object.send(:"#{state}_at=", Time.now) if object.respond_to?(:"#{state}_at=") && object.respond_to?(:"#{state}_at") && object.send(:"#{state}_at").nil?
+ object.send(:"#{state}_at=", now) if object.respond_to?(:"#{state}_at=") && object.respond_to?(:"#{state}_at") && object.send(:"#{state}_at").nil?
object.save! if @saving
end
end
@@ -84,6 +84,10 @@ def arity(object, method)
object.class.instance_method(method).arity rescue 0
end
+ def now
+ Time.respond_to?(:zone) && Time.zone ? Time.zone.now : Time.now.utc
+ end
+
def raise_invalid_transition(object)
raise TransitionException, "#{object.inspect} can not receive event #{name.inspect} while in state #{object.state.inspect}."
end
@@ -46,8 +46,6 @@ def merge_events(events)
if merge_ix = events.index { |event| event.name == :all }
merge = events.slice!(merge_ix)
events.each_with_index do |event, ix|
- # method = ? :append : :prepend
-
event.merge(merge, ix < merge_ix)
end
merge_events(events)
View
@@ -1,4 +1,5 @@
require 'test_helper'
+require 'active_support/core_ext/time/zones'
class StatesTest < Test::Unit::TestCase
include ClassCreateHelper

0 comments on commit b0a27b4

Please sign in to comment.