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
This commit is contained in:
nobu 2012-05-29 08:28:04 +00:00
Родитель 4f4de9b858
Коммит 60683816be
3 изменённых файлов: 31 добавлений и 18 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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