1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
shugo 2008-08-28 17:06:20 +00:00
parent c23ec90e81
commit 63846d48a9
4 changed files with 28 additions and 2 deletions

View file

@ -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.

View file

@ -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);

View file

@ -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"))

2
time.c
View file

@ -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