diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-28 17:06:20 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-28 17:06:20 +0000 |
commit | 63846d48a9b2044ad2fb3062ca8551de078d3508 (patch) | |
tree | b1691c2811825b84b9da5fd326abcc0d2034dd54 | |
parent | c23ec90e813457ec4db5d02677cdb358743974b5 (diff) | |
download | ruby-63846d48a9b2044ad2fb3062ca8551de078d3508.tar.gz |
* strftime.c (rb_strftime): supported %s and %P.
* time.c (time_strftime): ditto.
* test/ruby/test_time.rb (test_strftime): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | strftime.c | 10 | ||||
-rw-r--r-- | test/ruby/test_time.rb | 10 | ||||
-rw-r--r-- | time.c | 2 |
4 files changed, 28 insertions, 2 deletions
@@ -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")) @@ -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 |