1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #7703 from kennyj/fix_6962

Fix #6962. AS::TimeWithZone#strftime responds incorrectly to %:z and %::z format strings.
This commit is contained in:
Rafael Mendonça França 2012-09-20 06:34:55 -07:00
commit 883fa8f938
2 changed files with 12 additions and 1 deletions

View file

@ -168,7 +168,10 @@ module ActiveSupport
# Replaces <tt>%Z</tt> and <tt>%z</tt> directives with +zone+ and +formatted_offset+, respectively, before passing to # Replaces <tt>%Z</tt> and <tt>%z</tt> directives with +zone+ and +formatted_offset+, respectively, before passing to
# Time#strftime, so that zone information is correct # Time#strftime, so that zone information is correct
def strftime(format) def strftime(format)
format = format.gsub('%Z', zone).gsub('%z', formatted_offset(false)) format = format.gsub('%Z', zone)
.gsub('%z', formatted_offset(false))
.gsub('%:z', formatted_offset(true))
.gsub('%::z', formatted_offset(true) + ":00")
time.strftime(format) time.strftime(format)
end end

View file

@ -258,6 +258,14 @@ class TimeZoneTest < ActiveSupport::TestCase
assert_equal "-0500", zone.formatted_offset(false) assert_equal "-0500", zone.formatted_offset(false)
end end
def test_z_format_strings
zone = ActiveSupport::TimeZone['Tokyo']
twz = zone.now
assert_equal '+0900', twz.strftime('%z')
assert_equal '+09:00', twz.strftime('%:z')
assert_equal '+09:00:00', twz.strftime('%::z')
end
def test_formatted_offset_zero def test_formatted_offset_zero
zone = ActiveSupport::TimeZone['London'] zone = ActiveSupport::TimeZone['London']
assert_equal "+00:00", zone.formatted_offset assert_equal "+00:00", zone.formatted_offset