aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2013-06-08 08:22:29 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2013-06-08 09:50:15 +0100
commitb7f9de27f0558d6144f982cae83f32ca85a07f7e (patch)
tree1fe372c6c29f65141340cbf2835e0c34e8393e71 /activesupport/lib/active_support/core_ext
parentad3d333321d2cfdac87600f6440bc69b0945f37c (diff)
downloadrails-b7f9de27f0558d6144f982cae83f32ca85a07f7e.tar.gz
rails-b7f9de27f0558d6144f982cae83f32ca85a07f7e.tar.bz2
rails-b7f9de27f0558d6144f982cae83f32ca85a07f7e.zip
Override Time.at to work with Time-like values
Time.at allows passing a single Time argument which is then converted to an integer. The conversion code since 1.9.3r429 explicitly checks for an instance of Time so we need to override it to allow DateTime and ActiveSupport::TimeWithZone values.
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb
index a3ce7dbe3f..c65f20c2d5 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -65,6 +65,18 @@ class Time
def current
::Time.zone ? ::Time.zone.now : ::Time.now
end
+
+ # Layers additional behavior on Time.at so that ActiveSupport::TimeWithZone and DateTime
+ # instances can be used when called with a single argument
+ def at_with_coercion(*args)
+ if args.size == 1 && args.first.acts_like?(:time)
+ at_without_coercion(args.first.to_i)
+ else
+ at_without_coercion(*args)
+ end
+ end
+ alias_method :at_without_coercion, :at
+ alias_method :at, :at_with_coercion
end
# Seconds since midnight: Time.now.seconds_since_midnight