From 16dc9e04cbedff54c12235ae81121ce2f4acad1e Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 21 Apr 2009 16:43:15 +0000 Subject: [PATCH] * time.c (time_arg): use the year argument as-is. [ruby-dev:38194] * lib/time.rb (Time.parse): interpret small year 0..99 as 1950..2049. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ NEWS | 5 +++++ lib/time.rb | 16 +++++++++++++++- test/ruby/test_time.rb | 2 -- time.c | 17 +---------------- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index e1226f5016..8f280db71f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Apr 22 01:27:38 2009 Tanaka Akira + + * time.c (time_arg): use the year argument as-is. [ruby-dev:38194] + + * lib/time.rb (Time.parse): interpret small year 0..99 as 1950..2049. + Wed Apr 22 00:32:16 2009 Nobuyoshi Nakada * time.c (find_time_t): constified. diff --git a/NEWS b/NEWS index fb926b5906..8427bc1675 100644 --- a/NEWS +++ b/NEWS @@ -52,6 +52,11 @@ with all sufficient information, see the ChangeLog file. * time_t restriction is removed to represent before 1901 and after 2038. Proleptic Gregorian calendar is used for old dates. + * incompatible changes: + * The year argument of Time.{utc,gm,local,mktime} is now interpreted as + the value itself. For example, Time.utc(99) means the year 99 AD, + not 1999 AD. + * Kernel * extended methods: * respond_to? returns false for methods which simply raise diff --git a/lib/time.rb b/lib/time.rb index 031a4135ef..8a4d1ab2a8 100644 --- a/lib/time.rb +++ b/lib/time.rb @@ -258,7 +258,21 @@ class Time raise ArgumentError, "no time information in #{date.inspect}" end year = d[:year] - year = yield(year) if year && block_given? + if year + if block_given? + year = yield(year) + else + year = if year < 0 + year + elsif year < 50 + 2000 + year + elsif year < 100 + 1900 + year + else + year + end + end + end make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now) end diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index d9eaea6998..2bc03a631a 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -219,8 +219,6 @@ class TestTime < Test::Unit::TestCase def test_utc_or_local assert_equal(T2000, Time.gm(2000)) assert_equal(T2000, Time.gm(0, 0, 0, 1, 1, 2000, :foo, :bar, false, :baz)) - assert_equal(T2000, Time.gm(0)) - assert_equal(T2000, Time.gm(100)) assert_equal(T2000, Time.gm(2000, "jan")) assert_equal(T2000, Time.gm(2000, "1")) assert_equal(T2000, Time.gm(2000, 1, 1, 0, 0, 0, 0)) diff --git a/time.c b/time.c index a38ca544f5..f44229eea4 100644 --- a/time.c +++ b/time.c @@ -1398,8 +1398,6 @@ time_arg(int argc, VALUE *argv, struct vtm *vtm) { VALUE v[8]; int i; - long year; - VALUE x; vtm->year = INT2FIX(0); vtm->mon = 0; @@ -1432,20 +1430,7 @@ time_arg(int argc, VALUE *argv, struct vtm *vtm) vtm->isdst = -1; } - x = obj2vint(v[0]); - if (FIXNUM_P(x)) { - year = FIX2LONG(x); - if (0 <= year && year < 39) { - rb_warning("2 digits year is used: %ld", year); - year += 2000; - } - else if (69 <= year && year < 139) { - rb_warning("2 or 3 digits year is used: %ld", year); - year += 1900; - } - x = LONG2FIX(year); - } - vtm->year = x; + vtm->year = obj2vint(v[0]); if (NIL_P(v[1])) { vtm->mon = 1;