Skip to content
Browse files

Merge pull request #7703 from kennyj/fix_6962

Fix #6962. AS::TimeWithZone#strftime responds incorrectly to %:z and %::z format strings.
  • Loading branch information...
2 parents 2068d30 + 105cb3d commit 883fa8f938731e43182a803bedc89fd503a76306 @rafaelfranca rafaelfranca committed Sep 20, 2012
Showing with 12 additions and 1 deletion.
  1. +4 −1 activesupport/lib/active_support/time_with_zone.rb
  2. +8 −0 activesupport/test/time_zone_test.rb
View
5 activesupport/lib/active_support/time_with_zone.rb
@@ -168,7 +168,10 @@ def to_s(format = :default)
# 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
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
View
8 activesupport/test/time_zone_test.rb
@@ -258,6 +258,14 @@ def test_formatted_offset_negative
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

0 comments on commit 883fa8f

Please sign in to comment.
Something went wrong with that request. Please try again.