mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* strftime.c (rb_strftime_with_timespec): fix padding of time zone
offset. [ruby-dev:43287][Bug #4458] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
77321aeed9
commit
43dbbefbdf
3 changed files with 28 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Apr 17 22:18:48 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* strftime.c (rb_strftime_with_timespec): fix padding of time zone
|
||||
offset. [ruby-dev:43287][Bug #4458]
|
||||
|
||||
Tue Apr 17 13:11:14 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* dln.c (rb_w32_check_imported): skip ordinal entries. based on a
|
||||
|
|
10
strftime.c
10
strftime.c
|
@ -189,6 +189,9 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, rb_encodi
|
|||
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] = {
|
||||
|
@ -485,11 +488,12 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, rb_encodi
|
|||
}
|
||||
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;
|
||||
s += i;
|
||||
off = off % 3600;
|
||||
|
|
|
@ -668,6 +668,22 @@ 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)
|
||||
end
|
||||
|
||||
def test_delegate
|
||||
|
|
Loading…
Reference in a new issue