summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--strftime.c10
-rw-r--r--test/ruby/test_time.rb10
-rw-r--r--time.c2
4 files changed, 28 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index b71e911005..acb563623b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Fri Aug 29 02:03:56 2008 Shugo Maeda <shugo@ruby-lang.org>
+
+ * 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@fsij.org>
* transcode.c (sym_invalid_byte_sequence): new variable.
diff --git a/strftime.c b/strftime.c
index fa0e6e6a69..e559c05dd1 100644
--- a/strftime.c
+++ b/strftime.c
@@ -376,8 +376,10 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct tm *timept
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 @@ rb_strftime(char *s, size_t maxsize, const char *format, const struct tm *timept
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);
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index a2c2b1b140..3a9b055802 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -398,6 +398,8 @@ class TestTime < Test::Unit::TestCase
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 @@ class TestTime < Test::Unit::TestCase
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 @@ class TestTime < Test::Unit::TestCase
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"))
diff --git a/time.c b/time.c
index b111bca647..e54c655059 100644
--- a/time.c
+++ b/time.c
@@ -2091,6 +2091,8 @@ rb_strftime_alloc(char **buf, const char *format,
* %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