From c2b79c011f4ec39426c93812ab58660718c7cb92 Mon Sep 17 00:00:00 2001 From: shtirlic Date: Mon, 11 Jul 2011 18:41:04 +0400 Subject: Fix xmlschema output with fraction_digits >0 Current implementation produce incorrect output when Time#usec returns integer < 100000, because to_s doesn't add leading zeros. --- activesupport/lib/active_support/time_with_zone.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') 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')}" -- cgit v1.2.3