Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #6962. AS::TimeWithZone#strftime responds incorrectly to %:z and %::z format strings. #7703

Merged
merged 1 commit into from
Sep 20, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion activesupport/lib/active_support/time_with_zone.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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 # 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


Expand Down
8 changes: 8 additions & 0 deletions activesupport/test/time_zone_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ def test_formatted_offset_negative
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
Expand Down