diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 93c2d614f5..8c8f998f21 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -168,7 +168,10 @@ module ActiveSupport # Replaces %Z and %z directives with +zone+ and +formatted_offset+, respectively, before passing to # Time#strftime, so that zone information is correct 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) end diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index b9434489bb..bfd6863e40 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -258,6 +258,14 @@ class TimeZoneTest < ActiveSupport::TestCase assert_equal "-0500", zone.formatted_offset(false) 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 zone = ActiveSupport::TimeZone['London'] assert_equal "+00:00", zone.formatted_offset