1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* strftime.c (rb_strftime_with_timespec): %G produces 4 digits.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2011-01-30 07:10:55 +00:00
parent b4be48e88d
commit 2418e5ca83
3 changed files with 23 additions and 1 deletions

View file

@ -1,3 +1,7 @@
Sun Jan 30 16:09:22 2011 Tanaka Akira <akr@fsij.org>
* strftime.c (rb_strftime_with_timespec): %G produces 4 digits.
Sun Jan 30 15:13:19 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* enc/emacs_mule.c (emacsmule_islead): 7bit range is also leading

View file

@ -613,7 +613,13 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, const str
yv = sub(yv, INT2FIX(1));
if (*format == 'G') {
FMTV('0', 1, "d", yv);
if (FIXNUM_P(yv)) {
long y = FIX2LONG(yv);
FMT('0', 0 <= y ? 4 : 5, "ld", y);
}
else {
FMTV('0', 4, "d", yv);
}
}
else {
yv = mod(yv, INT2FIX(100));

View file

@ -590,6 +590,18 @@ class TestTime < Test::Unit::TestCase
assert_equal("02", t.strftime("%0l"))
assert_equal(" 2", t.strftime("%_l"))
t = Time.utc(1,1,4)
assert_equal("0001", t.strftime("%Y"))
assert_equal("0001", t.strftime("%G"))
t = Time.utc(0,1,4)
assert_equal("0000", t.strftime("%Y"))
assert_equal("0000", t.strftime("%G"))
t = Time.utc(-1,1,4)
assert_equal("-0001", t.strftime("%Y"))
assert_equal("-0001", t.strftime("%G"))
# [ruby-dev:37155]
t = Time.mktime(1970, 1, 18)
assert_equal("0", t.strftime("%w"))