[前][次][番号順一覧][スレッド一覧]

ruby-changes:23783

From: nobu <ko1@a...>
Date: Tue, 29 May 2012 17:28:16 +0900 (JST)
Subject: [ruby-changes:23783] nobu:r35834 (trunk): strftime.c: fix colon modifier.

nobu	2012-05-29 17:28:04 +0900 (Tue, 29 May 2012)

  New Revision: 35834

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35834

  Log:
    strftime.c: fix colon modifier.
    partially borrowed from ext/date.
    
    * strftime.c (rb_strftime_with_timespec): colons are valid only for
      'z' and must come just before it.

  Modified files:
    trunk/ChangeLog
    trunk/strftime.c
    trunk/test/ruby/test_time.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35833)
+++ ChangeLog	(revision 35834)
@@ -1,3 +1,8 @@
+Tue May 29 17:28:09 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* strftime.c (rb_strftime_with_timespec): colons are valid only for
+	  'z' and must come just before it.
+
 Mon May 28 16:56:55 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/test/unit.rb (Test::Unit::Runner#_prepare_run): StatusLineOutput
Index: strftime.c
===================================================================
--- strftime.c	(revision 35833)
+++ strftime.c	(revision 35834)
@@ -758,8 +758,12 @@
 			goto again;
 
 		case ':':
-			FLAG_FOUND();
-                        colons++;
+			{
+				size_t l = strspn(format, ":");
+				if (l > 3 || format[l] != 'z') goto unknown;
+				colons = (int)l;
+				format += l - 1;
+			}
 			goto again;
 
 		case '0':
Index: test/ruby/test_time.rb
===================================================================
--- test/ruby/test_time.rb	(revision 35833)
+++ test/ruby/test_time.rb	(revision 35834)
@@ -693,35 +693,39 @@
   def test_strftime_padding
     bug4458 = '[ruby-dev:43287]'
     t = T2000.getlocal("+09:00")
+    assert_equal("+0900", t.strftime("%z"))
+    assert_equal("+09:00", t.strftime("%:z"))
     assert_equal("      +900", t.strftime("%_10z"), bug4458)
     assert_equal("+000000900", t.strftime("%10z"), bug4458)
-    assert_equal("     +9:00", t.strftime("%_:10z"), bug4458)
-    assert_equal("+000009:00", t.strftime("%:10z"), bug4458)
-    assert_equal("  +9:00:00", t.strftime("%_::10z"), bug4458)
-    assert_equal("+009:00:00", t.strftime("%::10z"), bug4458)
+    assert_equal("     +9:00", t.strftime("%_10:z"), bug4458)
+    assert_equal("+000009:00", t.strftime("%10:z"), bug4458)
+    assert_equal("  +9:00:00", t.strftime("%_10::z"), bug4458)
+    assert_equal("+009:00:00", t.strftime("%10::z"), bug4458)
     t = T2000.getlocal("-05:00")
+    assert_equal("-0500", t.strftime("%z"))
+    assert_equal("-05:00", t.strftime("%:z"))
     assert_equal("      -500", t.strftime("%_10z"), bug4458)
     assert_equal("-000000500", t.strftime("%10z"), bug4458)
-    assert_equal("     -5:00", t.strftime("%_:10z"), bug4458)
-    assert_equal("-000005:00", t.strftime("%:10z"), bug4458)
-    assert_equal("  -5:00:00", t.strftime("%_::10z"), bug4458)
-    assert_equal("-005:00:00", t.strftime("%::10z"), bug4458)
+    assert_equal("     -5:00", t.strftime("%_10:z"), bug4458)
+    assert_equal("-000005:00", t.strftime("%10:z"), bug4458)
+    assert_equal("  -5:00:00", t.strftime("%_10::z"), bug4458)
+    assert_equal("-005:00:00", t.strftime("%10::z"), bug4458)
 
     bug6323 = '[ruby-core:44447]'
     t = T2000.getlocal("+00:36")
     assert_equal("      +036", t.strftime("%_10z"), bug6323)
     assert_equal("+000000036", t.strftime("%10z"), bug6323)
-    assert_equal("     +0:36", t.strftime("%_:10z"), bug6323)
-    assert_equal("+000000:36", t.strftime("%:10z"), bug6323)
-    assert_equal("  +0:36:00", t.strftime("%_::10z"), bug6323)
-    assert_equal("+000:36:00", t.strftime("%::10z"), bug6323)
+    assert_equal("     +0:36", t.strftime("%_10:z"), bug6323)
+    assert_equal("+000000:36", t.strftime("%10:z"), bug6323)
+    assert_equal("  +0:36:00", t.strftime("%_10::z"), bug6323)
+    assert_equal("+000:36:00", t.strftime("%10::z"), bug6323)
     t = T2000.getlocal("-00:55")
     assert_equal("      -055", t.strftime("%_10z"), bug6323)
     assert_equal("-000000055", t.strftime("%10z"), bug6323)
-    assert_equal("     -0:55", t.strftime("%_:10z"), bug6323)
-    assert_equal("-000000:55", t.strftime("%:10z"), bug6323)
-    assert_equal("  -0:55:00", t.strftime("%_::10z"), bug6323)
-    assert_equal("-000:55:00", t.strftime("%::10z"), bug6323)
+    assert_equal("     -0:55", t.strftime("%_10:z"), bug6323)
+    assert_equal("-000000:55", t.strftime("%10:z"), bug6323)
+    assert_equal("  -0:55:00", t.strftime("%_10::z"), bug6323)
+    assert_equal("-000:55:00", t.strftime("%10::z"), bug6323)
   end
 
   def test_delegate

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]