diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | lib/time.rb | 16 | ||||
-rw-r--r-- | test/ruby/test_time.rb | 2 | ||||
-rw-r--r-- | time.c | 17 |
5 files changed, 27 insertions, 19 deletions
@@ -1,3 +1,9 @@ +Wed Apr 22 01:27:38 2009 Tanaka Akira <akr@fsij.org> + + * 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 <nobu@ruby-lang.org> * time.c (find_time_t): constified. @@ -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)) @@ -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; |