ruby-changes:7388
From: shugo <ko1@a...>
Date: Fri, 29 Aug 2008 00:55:02 +0900 (JST)
Subject: [ruby-changes:7388] Ruby:r18907 (trunk): * strftime.c (rb_strftime): fixed a bug of padding.
shugo 2008-08-29 00:54:44 +0900 (Fri, 29 Aug 2008) New Revision: 18907 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18907 Log: * strftime.c (rb_strftime): fixed a bug of padding. * test/ruby/test_time.rb: ditto. Modified files: trunk/ChangeLog trunk/strftime.c trunk/test/ruby/test_time.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 18906) +++ ChangeLog (revision 18907) @@ -1,3 +1,9 @@ +Fri Aug 29 00:53:40 2008 Shugo Maeda <shugo@r...> + + * strftime.c (rb_strftime): fixed a bug of padding. + + * test/ruby/test_time.rb: ditto. + Fri Aug 29 00:19:54 2008 NAKAMURA Usaku <usa@r...> * win32/win32.c (set_pioinfo_extra): use MSVCRT's open() and close(). Index: strftime.c =================================================================== --- strftime.c (revision 18906) +++ strftime.c (revision 18907) @@ -277,7 +277,7 @@ if (precision <= 0) precision = (def_prec); \ if (flags & BIT_OF(LEFT)) precision = 1; \ l = snprintf(s, endp - s, \ - ((!padding || padding == (def_pad)) ? "%.*"fmt : "%*"fmt), \ + ((padding == '0' || (!padding && def_pad == '0')) ? "%.*"fmt : "%*"fmt), \ precision, val); \ if (l < 0) goto err; \ s += l; \ Index: test/ruby/test_time.rb =================================================================== --- test/ruby/test_time.rb (revision 18906) +++ test/ruby/test_time.rb (revision 18907) @@ -401,5 +401,38 @@ t = Time.mktime(2001, 10, 1) assert_equal("2001-10-01", t.strftime("%F")) + + t = Time.mktime(2001, 10, 1, 2, 0, 0) + assert_equal("01", t.strftime("%d")) + assert_equal("01", t.strftime("%0d")) + assert_equal(" 1", t.strftime("%_d")) + assert_equal(" 1", t.strftime("%e")) + assert_equal("01", t.strftime("%0e")) + assert_equal(" 1", t.strftime("%_e")) + assert_equal("02", t.strftime("%H")) + assert_equal("02", t.strftime("%0H")) + assert_equal(" 2", t.strftime("%_H")) + assert_equal("02", t.strftime("%I")) + assert_equal("02", t.strftime("%0I")) + assert_equal(" 2", t.strftime("%_I")) + assert_equal(" 2", t.strftime("%k")) + assert_equal("02", t.strftime("%0k")) + assert_equal(" 2", t.strftime("%_k")) + assert_equal(" 2", t.strftime("%l")) + assert_equal("02", t.strftime("%0l")) + assert_equal(" 2", t.strftime("%_l")) + t = Time.mktime(2001, 10, 1, 14, 0, 0) + assert_equal("14", t.strftime("%H")) + assert_equal("14", t.strftime("%0H")) + assert_equal("14", t.strftime("%_H")) + assert_equal("02", t.strftime("%I")) + assert_equal("02", t.strftime("%0I")) + assert_equal(" 2", t.strftime("%_I")) + assert_equal("14", t.strftime("%k")) + assert_equal("14", t.strftime("%0k")) + assert_equal("14", t.strftime("%_k")) + assert_equal(" 2", t.strftime("%l")) + assert_equal("02", t.strftime("%0l")) + assert_equal(" 2", t.strftime("%_l")) end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/