diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2014-01-26 21:22:23 +0000 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2014-01-26 21:25:54 +0000 |
commit | dd339bb0adc3bb1f0c376c4352f769ae2ab02b62 (patch) | |
tree | 84d91b89bcc7ea9861edd5a3ce8f57772f34fff4 | |
parent | c0965004486f2ea5a9656ba718a3377c9614f97d (diff) | |
download | rails-dd339bb0adc3bb1f0c376c4352f769ae2ab02b62.tar.gz rails-dd339bb0adc3bb1f0c376c4352f769ae2ab02b62.tar.bz2 rails-dd339bb0adc3bb1f0c376c4352f769ae2ab02b62.zip |
Make ActiveSupport::TimeWithZone#xmlschema consistent
Both Time#xmlschema and DateTime#xmlschema can accept nil values for the
fraction_digits parameter. This commit makes this so for TimeWithZone
values as well.
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 626438c9e4..d459af1778 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -132,8 +132,8 @@ module ActiveSupport end def xmlschema(fraction_digits = 0) - fraction = if fraction_digits > 0 - (".%06i" % time.usec)[0, fraction_digits + 1] + fraction = if fraction_digits.to_i > 0 + (".%06i" % time.usec)[0, fraction_digits.to_i + 1] end "#{time.strftime("%Y-%m-%dT%H:%M:%S")}#{fraction}#{formatted_offset(true, 'Z')}" diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index e9bf43667a..8e25f1e2f2 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -111,6 +111,10 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_equal "1999-12-31T19:00:00.001234-05:00", @twz.xmlschema(12) end + def test_xmlschema_with_nil_fractional_seconds + assert_equal "1999-12-31T19:00:00-05:00", @twz.xmlschema(nil) + end + def test_to_yaml assert_match(/^--- 2000-01-01 00:00:00(\.0+)?\s*Z\n/, @twz.to_yaml) end |