diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-05-29 08:28:04 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-05-29 08:28:04 +0000 |
commit | 60683816be0674fc3e0a07855f5c2de68c4db771 (patch) | |
tree | e314f18ee8e59773b733edd357df6b32bf51caca | |
parent | 4f4de9b858a3336e065b31dd7fa338d02a8a29eb (diff) | |
download | ruby-60683816be0674fc3e0a07855f5c2de68c4db771.tar.gz |
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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | strftime.c | 8 | ||||
-rw-r--r-- | test/ruby/test_time.rb | 36 |
3 files changed, 31 insertions, 18 deletions
@@ -1,3 +1,8 @@ +Tue May 29 17:28:09 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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@ruby-lang.org> * lib/test/unit.rb (Test::Unit::Runner#_prepare_run): StatusLineOutput diff --git a/strftime.c b/strftime.c index ba65c87502..767a852727 100644 --- a/strftime.c +++ b/strftime.c @@ -758,8 +758,12 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, rb_encodi 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': diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index c45a2cc087..a5087bcbfa 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -693,35 +693,39 @@ class TestTime < Test::Unit::TestCase 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 |