summaryrefslogtreecommitdiff
path: root/strftime.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-20 22:16:21 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-20 22:16:21 +0000
commita834d7fe61fa307e47984022184195652799fc32 (patch)
tree9c884477e515d16110d42740dacdc1859f455841 /strftime.c
parenteaa1fccf1dbb92a78b5e4398f5f34659d58a1662 (diff)
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
Diffstat (limited to 'strftime.c')
-rw-r--r--strftime.c13
1 files changed, 10 insertions, 3 deletions
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)