From a834d7fe61fa307e47984022184195652799fc32 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 20 Apr 2012 22:16:21 +0000 Subject: merge revision(s) 35366,35377,35399,35406: * strftime.c (rb_strftime_with_timespec): fix padding of time zone offset. [ruby-dev:43287][Bug #4458] * strftime.c (rb_strftime_with_timespec): add an interim digit for the timezone offset which is less than an hour. * strftime.c (rb_strftime_with_timespec): fix carry-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/branches/ruby_1_9_3@35416 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 12 ++++++++++++ strftime.c | 13 ++++++++++--- test/ruby/test_time.rb | 32 ++++++++++++++++++++++++++++++++ version.h | 6 +++--- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index fb7448fcf8..3dcf009b33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Sat Apr 21 07:16:16 2012 Nobuyoshi Nakada + + * strftime.c (rb_strftime_with_timespec): fix padding of time zone + offset. [ruby-dev:43287][Bug #4458] + + * strftime.c (rb_strftime_with_timespec): add an interim digit for + the timezone offset which is less than an hour. + + * strftime.c (rb_strftime_with_timespec): fix carry-up bug and + overwrite '+' with '-' if negative offset less than a hour. + [ruby-core:44447][Bug #6323] + Fri Apr 20 12:30:06 2012 Eric Hodel * lib/rubygems/ssl_certs/AddTrustExternalCARoot.pem: Removed to avoid diff --git a/strftime.c b/strftime.c index 1164db01d1..4222daa263 100644 --- a/strftime.c +++ b/strftime.c @@ -182,6 +182,9 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, const str char padding; enum {LEFT, CHCASE, LOWER, UPPER, LOCALE_O, LOCALE_E}; #define BIT_OF(n) (1U<<(n)) +#ifdef MAILHEADER_EXT + int sign; +#endif /* various tables, useful in North America */ static const char days_l[][10] = { @@ -473,12 +476,16 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, const str } if (off < 0) { off = -off; - *s++ = '-'; + sign = -1; } else { - *s++ = '+'; + sign = +1; } - i = snprintf(s, endp - s, (padding == ' ' ? "%*ld" : "%.*ld"), precision, off / 3600); + i = snprintf(s, endp - s, (padding == ' ' ? "%+*ld" : "%+.*ld"), + precision + 1, sign * (off / 3600)); if (i < 0) goto err; + if (sign < 0 && off < 3600) { + *(padding == ' ' ? s + i - 2 : s) = '-'; + } s += i; off = off % 3600; if (1 <= colons) diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index a1f060ec85..2edba516fe 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -659,6 +659,38 @@ class TestTime < Test::Unit::TestCase bug4457 = '[ruby-dev:43285]' assert_raise(Errno::ERANGE, bug4457) {Time.now.strftime('%8192z')} + + bug4458 = '[ruby-dev:43287]' + t = T2000.getlocal("+09:00") + 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) + t = T2000.getlocal("-05:00") + 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) + + 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 diff --git a/version.h b/version.h index 64de5c9805..0b2edb89d6 100644 --- a/version.h +++ b/version.h @@ -1,10 +1,10 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 195 +#define RUBY_PATCHLEVEL 196 -#define RUBY_RELEASE_DATE "2012-04-20" +#define RUBY_RELEASE_DATE "2012-04-21" #define RUBY_RELEASE_YEAR 2012 #define RUBY_RELEASE_MONTH 4 -#define RUBY_RELEASE_DAY 20 +#define RUBY_RELEASE_DAY 21 #include "ruby/version.h" -- cgit v1.2.3