diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-04-19 07:33:55 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-04-19 07:33:55 +0000 |
commit | e0ffb9b59be89bc0434ebeacafa2bb0160306423 (patch) | |
tree | e8dd4a1ca07f9d71565fe58c958cd37d11acb1d5 | |
parent | ec0bd633e274544391d5f7899d0bfd5b7c63f872 (diff) | |
download | ruby-e0ffb9b59be89bc0434ebeacafa2bb0160306423.tar.gz |
* strftime.c (rb_strftime_with_timespec): fix carrir-up bug and
overwrite '+' with '-' if negative offset less than a hour.
[ruby-core:44447][Bug #6323]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35399 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | strftime.c | 7 | ||||
-rw-r--r-- | test/ruby/test_time.rb | 16 |
3 files changed, 27 insertions, 2 deletions
@@ -1,3 +1,9 @@ +Thu Apr 19 16:33:53 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * strftime.c (rb_strftime_with_timespec): fix carrir-up bug and + overwrite '+' with '-' if negative offset less than a hour. + [ruby-core:44447][Bug #6323] + Thu Apr 19 09:39:57 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> * ext/-test-/win32/dln/extconf.rb: need import library for ordinal diff --git a/strftime.c b/strftime.c index ea369deaa0..8be95a310b 100644 --- a/strftime.c +++ b/strftime.c @@ -493,9 +493,12 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, rb_encodi sign = +1; } i = snprintf(s, endp - s, (padding == ' ' ? "%+*ld" : "%+.*ld"), - precision + 2, sign * (off / 360 + 1)); + precision + 1, sign * (off / 3600)); if (i < 0) goto err; - s += i - 1; + if (sign < 0 && off < 3600) { + *(padding == ' ' ? s + i - 2 : s) = '-'; + } + s += i; off = off % 3600; if (1 <= colons) *s++ = ':'; diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index 573b563177..10ee8fe798 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -684,6 +684,22 @@ class TestTime < Test::Unit::TestCase 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) + + 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) + 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) end def test_delegate |