aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-05-30 15:32:37 -0400
committerGitHub <noreply@github.com>2018-05-30 15:32:37 -0400
commite6ef1fe056d7da084a4e8d3b817223e9a28e6200 (patch)
tree95cd282f1006df325150acd41ee42fc6f8f622ee /activesupport
parent16574409f813e2197f88e4a06b527618d64d9ff0 (diff)
parent45762cec03ee1218d5a257d2920678f37bd9bdb4 (diff)
downloadrails-e6ef1fe056d7da084a4e8d3b817223e9a28e6200.tar.gz
rails-e6ef1fe056d7da084a4e8d3b817223e9a28e6200.tar.bz2
rails-e6ef1fe056d7da084a4e8d3b817223e9a28e6200.zip
Merge pull request #33020 from joshpencheon/time_zone_frac_microseconds
Align Time.zone.at method signature with that of Time::at
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb9
-rw-r--r--activesupport/test/time_zone_test.rb10
2 files changed, 17 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 5f709c5fd9..792c88415c 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -354,8 +354,13 @@ module ActiveSupport
# Time.zone = 'Hawaii' # => "Hawaii"
# Time.utc(2000).to_f # => 946684800.0
# Time.zone.at(946684800.0) # => Fri, 31 Dec 1999 14:00:00 HST -10:00
- def at(secs)
- Time.at(secs).utc.in_time_zone(self)
+ #
+ # A second argument can be supplied to specify sub-second precision.
+ #
+ # Time.zone = 'Hawaii' # => "Hawaii"
+ # Time.at(946684800, 123456.789).nsec # => 123456789
+ def at(*args)
+ Time.at(*args).utc.in_time_zone(self)
end
# Method for creating new ActiveSupport::TimeWithZone instance in time zone
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
index b59f3e9405..6d45a6726d 100644
--- a/activesupport/test/time_zone_test.rb
+++ b/activesupport/test/time_zone_test.rb
@@ -225,6 +225,16 @@ class TimeZoneTest < ActiveSupport::TestCase
assert_equal secs, twz.to_f
end
+ def test_at_with_microseconds
+ zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"]
+ secs = 946684800.0
+ microsecs = 123456.789
+ twz = zone.at(secs, microsecs)
+ assert_equal zone, twz.time_zone
+ assert_equal secs, twz.to_i
+ assert_equal 123456789, twz.nsec
+ end
+
def test_iso8601
zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"]
twz = zone.iso8601("1999-12-31T19:00:00")