Skip to content

Instantly share code, notes, and snippets.

@eregon
Created January 10, 2014 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eregon/969d6d7afbf069d8b4d1 to your computer and use it in GitHub Desktop.
Save eregon/969d6d7afbf069d8b4d1 to your computer and use it in GitHub Desktop.
diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb
index 8e5d723..487f8d9 100644
--- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb
@@ -151,7 +151,7 @@ class DateTime
# Layers additional behavior on DateTime#<=> so that Time and
# ActiveSupport::TimeWithZone instances can be compared with a DateTime.
def <=>(other)
- super other.to_datetime
+ super other.to_datetime if other.respond_to? :to_datetime
end
end
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index 50db7da..b799ca0 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -69,8 +69,9 @@ module ActiveSupport
# Returns the simultaneous time in <tt>Time.zone</tt>, or the specified zone.
def in_time_zone(new_zone = ::Time.zone)
- return self if time_zone == new_zone
- utc.in_time_zone(new_zone)
+ new_time_zone = ::Time.find_zone! new_zone
+ return self if time_zone == new_time_zone
+ utc.in_time_zone(new_time_zone)
end
# Returns a <tt>Time.local()</tt> instance of the simultaneous time in your
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment