ruby-changes:14092
From: akr <ko1@a...>
Date: Tue, 24 Nov 2009 20:35:04 +0900 (JST)
Subject: [ruby-changes:14092] Ruby:r25906 (trunk): * strftime.c: %Y format a year with 4 digits at least.
akr 2009-11-24 20:34:45 +0900 (Tue, 24 Nov 2009) New Revision: 25906 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25906 Log: * strftime.c: %Y format a year with 4 digits at least. * lib/time.rb: format a year with 4 digits at least. Modified files: trunk/ChangeLog trunk/lib/time.rb trunk/strftime.c trunk/test/test_time.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 25905) +++ ChangeLog (revision 25906) @@ -1,3 +1,9 @@ +Tue Nov 24 20:11:37 2009 Tanaka Akira <akr@f...> + + * strftime.c: %Y format a year with 4 digits at least. + + * lib/time.rb: format a year with 4 digits at least. + Tue Nov 24 20:05:27 2009 Tanaka Akira <akr@f...> * defs/known_errors.def: more errors. Index: lib/time.rb =================================================================== --- lib/time.rb (revision 25905) +++ lib/time.rb (revision 25906) @@ -432,9 +432,9 @@ # If +self+ is a UTC time, -0000 is used as zone. # def rfc2822 - sprintf('%s, %02d %s %04d %02d:%02d:%02d ', + sprintf('%s, %02d %s %0*d %02d:%02d:%02d ', RFC2822_DAY_NAME[wday], - day, RFC2822_MONTH_NAME[mon-1], year, + day, RFC2822_MONTH_NAME[mon-1], year < 0 ? 5 : 4, year, hour, min, sec) + if utc? '-0000' @@ -464,9 +464,9 @@ # def httpdate t = dup.utc - sprintf('%s, %02d %s %04d %02d:%02d:%02d GMT', + sprintf('%s, %02d %s %0*d %02d:%02d:%02d GMT', RFC2822_DAY_NAME[t.wday], - t.day, RFC2822_MONTH_NAME[t.mon-1], t.year, + t.day, RFC2822_MONTH_NAME[t.mon-1], t.year < 0 ? 5 : 4, t.year, t.hour, t.min, t.sec) end @@ -485,8 +485,8 @@ # Its default value is 0. # def xmlschema(fraction_digits=0) - sprintf('%04d-%02d-%02dT%02d:%02d:%02d', - year, mon, day, hour, min, sec) + + sprintf('%0*d-%02d-%02dT%02d:%02d:%02d', + year < 0 ? 5 : 4, year, mon, day, hour, min, sec) + if fraction_digits == 0 '' else Index: strftime.c =================================================================== --- strftime.c (revision 25905) +++ strftime.c (revision 25906) @@ -496,7 +496,13 @@ continue; case 'Y': /* year with century */ - FMTV('0', 1, "d", vtm->year); + if (FIXNUM_P(vtm->year)) { + long y = FIX2LONG(vtm->year); + FMT('0', 0 <= y ? 4 : 5, "ld", y); + } + else { + FMTV('0', 4, "d", vtm->year); + } continue; #ifdef MAILHEADER_EXT Index: test/test_time.rb =================================================================== --- test/test_time.rb (revision 25905) +++ test/test_time.rb (revision 25906) @@ -188,6 +188,15 @@ end assert_equal(249, Time.xmlschema("2008-06-05T23:49:23.000249+09:00").usec) + + assert_equal("10000-01-01T00:00:00Z", Time.utc(10000).xmlschema) + assert_equal("9999-01-01T00:00:00Z", Time.utc(9999).xmlschema) + assert_equal("0001-01-01T00:00:00Z", Time.utc(1).xmlschema) # 1 AD + assert_equal("0000-01-01T00:00:00Z", Time.utc(0).xmlschema) # 1 BC + assert_equal("-0001-01-01T00:00:00Z", Time.utc(-1).xmlschema) # 2 BC + assert_equal("-0004-01-01T00:00:00Z", Time.utc(-4).xmlschema) # 5 BC + assert_equal("-9999-01-01T00:00:00Z", Time.utc(-9999).xmlschema) + assert_equal("-10000-01-01T00:00:00Z", Time.utc(-10000).xmlschema) end def test_completion -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/