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

ruby-changes:7390

From: shugo <ko1@a...>
Date: Fri, 29 Aug 2008 02:06:37 +0900 (JST)
Subject: [ruby-changes:7390] Ruby:r18909 (trunk): * strftime.c (rb_strftime): supported %s and %P.

shugo	2008-08-29 02:06:20 +0900 (Fri, 29 Aug 2008)

  New Revision: 18909

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

  Log:
    * strftime.c (rb_strftime): supported %s and %P.
    * time.c (time_strftime): ditto.
    * test/ruby/test_time.rb (test_strftime): ditto.

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

Index: time.c
===================================================================
--- time.c	(revision 18908)
+++ time.c	(revision 18909)
@@ -2091,6 +2091,8 @@
  *            %6N  microsecond (6 digits)
  *            %9N  nanosecond (9 digits)
  *    %p - Meridian indicator (``AM''  or  ``PM'')
+ *    %P - Meridian indicator (``am''  or  ``pm'')
+ *    %s - Number of seconds since 1970-01-01 00:00:00 UTC.
  *    %S - Second of the minute (00..60)
  *    %U - Week  number  of the current year,
  *            starting with the first Sunday as the first
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18908)
+++ ChangeLog	(revision 18909)
@@ -1,3 +1,11 @@
+Fri Aug 29 02:03:56 2008  Shugo Maeda  <shugo@r...>
+
+	* strftime.c (rb_strftime): supported %s and %P.
+
+	* time.c (time_strftime): ditto.
+
+	* test/ruby/test_time.rb (test_strftime): ditto.
+
 Fri Aug 29 01:57:58 2008  Tanaka Akira  <akr@f...>
 
 	* transcode.c (sym_invalid_byte_sequence): new variable.
Index: strftime.c
===================================================================
--- strftime.c	(revision 18908)
+++ strftime.c	(revision 18909)
@@ -376,8 +376,10 @@
 			FMT('0', 2, "d", i);
 			continue;
 
-		case 'p':	/* am or pm based on 12-hour clock */
-			if (flags & BIT_OF(CHCASE)) {
+		case 'p':	/* AM or PM based on 12-hour clock */
+		case 'P':	/* am or pm based on 12-hour clock */
+			if ((*format == 'p' && (flags & BIT_OF(CHCASE))) ||
+			    (*format == 'P' && !(flags & BIT_OF(CHCASE)))) {
 				flags &= ~(BIT_OF(UPPER)|BIT_OF(CHCASE));
 				flags |= BIT_OF(LOWER);
 			}
@@ -389,6 +391,10 @@
 			i = 2;
 			break;
 
+		case 's':
+			FMT(' ', 1, "d", (int) ts->tv_sec);
+			continue;
+
 		case 'S':	/* second, 00 - 60 */
 			i = range(0, timeptr->tm_sec, 60);
 			FMT('0', 2, "d", i);
Index: test/ruby/test_time.rb
===================================================================
--- test/ruby/test_time.rb	(revision 18908)
+++ test/ruby/test_time.rb	(revision 18909)
@@ -398,6 +398,8 @@
     assert_equal("1234567890", t.strftime("%10N"))
     assert_equal("", t.strftime("%0N"))
     assert_equal("000", t.strftime("%3S"))
+    assert_equal("946684800", t.strftime("%s"))
+    assert_equal("946684800", t.utc.strftime("%s"))
 
     t = Time.mktime(2001, 10, 1)
     assert_equal("2001-10-01", t.strftime("%F"))
@@ -409,6 +411,10 @@
     assert_equal(" 1", t.strftime("%e"))
     assert_equal("01", t.strftime("%0e"))
     assert_equal(" 1", t.strftime("%_e"))
+    assert_equal("AM", t.strftime("%p"))
+    assert_equal("am", t.strftime("%#p"))
+    assert_equal("am", t.strftime("%P"))
+    assert_equal("AM", t.strftime("%#P"))
     assert_equal("02", t.strftime("%H"))
     assert_equal("02", t.strftime("%0H"))
     assert_equal(" 2", t.strftime("%_H"))
@@ -422,6 +428,10 @@
     assert_equal("02", t.strftime("%0l"))
     assert_equal(" 2", t.strftime("%_l"))
     t = Time.mktime(2001, 10, 1, 14, 0, 0)
+    assert_equal("PM", t.strftime("%p"))
+    assert_equal("pm", t.strftime("%#p"))
+    assert_equal("pm", t.strftime("%P"))
+    assert_equal("PM", t.strftime("%#P"))
     assert_equal("14", t.strftime("%H"))
     assert_equal("14", t.strftime("%0H"))
     assert_equal("14", t.strftime("%_H"))

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

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