Allow Time.zone.at to receive a second argument

For parity with Ruby's Time::at
This commit is contained in:
Josh Pencheon 2018-05-30 13:42:07 +01:00
parent 0d7f13a622
commit 45762cec03
2 changed files with 17 additions and 2 deletions

View File

@ -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

View File

@ -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")