aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-30 07:10:55 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-30 07:10:55 +0000
commit2418e5ca83f863b58a9e13caefc9a23414cae49c (patch)
tree7a17ed7568b11f3d56216ad93265e6793f81cf9e
parentb4be48e88d74c1e5cce9d68aed30c4e4ef17d7c5 (diff)
downloadruby-2418e5ca83f863b58a9e13caefc9a23414cae49c.tar.gz
* 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
-rw-r--r--ChangeLog4
-rw-r--r--strftime.c8
-rw-r--r--test/ruby/test_time.rb12
3 files changed, 23 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index ad5d2e4a73..3d0661eb0a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/strftime.c b/strftime.c
index 289f6ed48a..dc6df615d7 100644
--- a/strftime.c
+++ b/strftime.c
@@ -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));
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index ec5395092f..838a7692f7 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -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"))