Add ActiveSupport::TimeZone#dst?
Like abbr, this is used by Ruby when specifying creating a ::Time with a zone object.
This commit is contained in:
parent
262713413c
commit
edc7018742
@ -574,6 +574,12 @@ def abbr(time)
|
||||
tzinfo.abbr(time)
|
||||
end
|
||||
|
||||
# Available so that TimeZone instances respond like +TZInfo::Timezone+
|
||||
# instances.
|
||||
def dst?(time)
|
||||
tzinfo.dst?(time)
|
||||
end
|
||||
|
||||
def init_with(coder) # :nodoc:
|
||||
initialize(coder["name"])
|
||||
end
|
||||
|
@ -886,4 +886,38 @@ def test_abbr
|
||||
assert_equal "EST", zone.abbr(Time.utc(2000, 10, 29, 6))
|
||||
assert_equal "EST", zone.abbr(Time.utc(2000, 10, 29, 7))
|
||||
end
|
||||
|
||||
def test_dst
|
||||
zone = ActiveSupport::TimeZone["America/Toronto"]
|
||||
assert_equal false, zone.dst?(Time.utc(2000, 4, 2, 6))
|
||||
assert_equal true, zone.dst?(Time.utc(2000, 4, 2, 7))
|
||||
assert_equal true, zone.dst?(Time.utc(2000, 4, 2, 8))
|
||||
assert_equal true, zone.dst?(Time.utc(2000, 10, 29, 5))
|
||||
assert_equal false, zone.dst?(Time.utc(2000, 10, 29, 6))
|
||||
assert_equal false, zone.dst?(Time.utc(2000, 10, 29, 7))
|
||||
end
|
||||
|
||||
def test_works_as_ruby_time_zone
|
||||
zone = ActiveSupport::TimeZone["America/Toronto"]
|
||||
time = Time.new(2000, 1, 1, 1, in: zone)
|
||||
assert_same zone, time.zone
|
||||
assert_equal "2000-01-01T01:00:00-05:00", time.iso8601
|
||||
assert_equal(-18000, time.utc_offset)
|
||||
assert_equal "EST", time.strftime("%Z")
|
||||
assert_equal false, time.isdst
|
||||
|
||||
time = Time.new(2000, 6, 1, 1, in: zone)
|
||||
assert_same zone, time.zone
|
||||
assert_equal "2000-06-01T01:00:00-04:00", time.iso8601
|
||||
assert_equal(-14400, time.utc_offset)
|
||||
assert_equal "EDT", time.strftime("%Z")
|
||||
assert_equal true, time.isdst
|
||||
|
||||
time = Time.at(959835600, in: zone)
|
||||
assert_same zone, time.zone
|
||||
assert_equal "2000-06-01T01:00:00-04:00", time.iso8601
|
||||
assert_equal(-14400, time.utc_offset)
|
||||
assert_equal "EDT", time.strftime("%Z")
|
||||
assert_equal true, time.isdst
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user