Permalink
Browse files

handle rails time objects too :(

  • Loading branch information...
mkristian committed Jan 2, 2013
1 parent 29c8f2f commit 8ee4359939b2d8aec40b709253000e05c92a6c4d
Showing with 5 additions and 2 deletions.
  1. +5 −2 lib/ixtlan/optimistic/stale_check.rb
@@ -30,11 +30,14 @@ def __check( updated_at )
end
def __check_stale( updated_at, result )
- if updated_at.is_a?( String )
+ if updated_at.is_a? String
updated_at = DateTime.parse( updated_at.sub(/[.][0-9]+/, '') )
end
+ if defined?( ActiveSupport ) && updated_at.is_a?( ActiveSupport::TimeWithZone )
+ updated_at = updated_at.to_datetime
+ end
updated_at = updated_at.new_offset(0)
- if updated_at != result.updated_at && updated_at.strftime("%Y:%m:%d %H:%M:%S") != result.updated_at.new_offset(0).strftime("%Y:%m:%d %H:%M:%S")
+ if updated_at != result.updated_at && updated_at.strftime("%Y:%m:%d %H:%M:%S") != result.updated_at.strftime("%Y:%m:%d %H:%M:%S")
raise ObjectStaleException.new "#{result.inspect} is stale for updated at #{updated_at}."
end

0 comments on commit 8ee4359

Please sign in to comment.