ruby-changes:11611
From: akr <ko1@a...>
Date: Wed, 22 Apr 2009 02:12:42 +0900 (JST)
Subject: [ruby-changes:11611] Ruby:r23248 (trunk): * lib/time.rb (Time#xmlschema): use subsec instead of nsec.
akr 2009-04-22 02:11:27 +0900 (Wed, 22 Apr 2009) New Revision: 23248 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23248 Log: * lib/time.rb (Time#xmlschema): use subsec instead of nsec. Modified files: trunk/ChangeLog trunk/lib/time.rb trunk/test/test_time.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 23247) +++ ChangeLog (revision 23248) @@ -1,3 +1,7 @@ +Wed Apr 22 02:10:48 2009 Tanaka Akira <akr@f...> + + * lib/time.rb (Time#xmlschema): use subsec instead of nsec. + Wed Apr 22 01:27:38 2009 Tanaka Akira <akr@f...> * time.c (time_arg): use the year argument as-is. [ruby-dev:38194] Index: lib/time.rb =================================================================== --- lib/time.rb (revision 23247) +++ lib/time.rb (revision 23248) @@ -502,10 +502,8 @@ year, mon, day, hour, min, sec) + if fraction_digits == 0 '' - elsif fraction_digits <= 9 - '.' + sprintf('%09d', nsec)[0, fraction_digits] else - '.' + sprintf('%09d', nsec) + '0' * (fraction_digits - 9) + '.' + sprintf('%0*d', fraction_digits, (subsec * 10**fraction_digits).floor) end + if utc? 'Z' Index: test/test_time.rb =================================================================== --- test/test_time.rb (revision 23247) +++ test/test_time.rb (revision 23248) @@ -153,6 +153,18 @@ assert_equal("2001-04-17T19:23:17.12345Z", t.xmlschema(5)) assert_equal("2001-04-17T19:23:17.1Z", t.xmlschema(1)) + t = Time.at(2.quo(3)) + assert_equal("1970-01-01T09:00:00.666+09:00", t.xmlschema(3)) + assert_equal("1970-01-01T09:00:00.6666666666+09:00", t.xmlschema(10)) + assert_equal("1970-01-01T09:00:00.66666666666666666666+09:00", t.xmlschema(20)) + + t = Time.at(123456789.quo(9999999999)) + assert_equal("1970-01-01T09:00:00.012+09:00", t.xmlschema(3)) + assert_equal("1970-01-01T09:00:00.012345678+09:00", t.xmlschema(9)) + assert_equal("1970-01-01T09:00:00.0123456789+09:00", t.xmlschema(10)) + assert_equal("1970-01-01T09:00:00.0123456789012345678+09:00", t.xmlschema(19)) + assert_equal("1970-01-01T09:00:00.01234567890123456789+09:00", t.xmlschema(20)) + begin Time.at(-1) rescue ArgumentError -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/