diff options
author | José Valim <jose.valim@gmail.com> | 2011-07-11 10:00:28 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-07-11 10:00:28 -0700 |
commit | 133a20354ef9872721e3b825daaf8eca686b4d37 (patch) | |
tree | 6da752150911805da2427a0878e06979040cb32d /activesupport | |
parent | 91bba2181576c32bda4825741beb94c58395736d (diff) | |
parent | c2b79c011f4ec39426c93812ab58660718c7cb92 (diff) | |
download | rails-133a20354ef9872721e3b825daaf8eca686b4d37.tar.gz rails-133a20354ef9872721e3b825daaf8eca686b4d37.tar.bz2 rails-133a20354ef9872721e3b825daaf8eca686b4d37.zip |
Merge pull request #1756 from shtirlic/xmlschema_fix
Fix xmlschema output with fraction_digits >0
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 3d092529d6..ec2c717942 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -109,7 +109,7 @@ module ActiveSupport def xmlschema(fraction_digits = 0) fraction = if fraction_digits > 0 - ".%i" % time.usec.to_s[0, fraction_digits] + (".%06i" % time.usec)[0, fraction_digits + 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 72b55183ba..b2309ae806 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -111,6 +111,13 @@ class TimeWithZoneTest < Test::Unit::TestCase assert_equal "1999-12-31T19:00:00.123456-05:00", @twz.xmlschema(12) end + def test_xmlschema_with_fractional_seconds_lower_than_hundred_thousand + @twz += 0.001234 # advance the time by a fraction + assert_equal "1999-12-31T19:00:00.001-05:00", @twz.xmlschema(3) + assert_equal "1999-12-31T19:00:00.001234-05:00", @twz.xmlschema(6) + assert_equal "1999-12-31T19:00:00.001234-05:00", @twz.xmlschema(12) + end + def test_to_yaml assert_match(/^--- 2000-01-01 00:00:00(\.0+)?\s*Z\n/, @twz.to_yaml) end |