* 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
This commit is contained in:
akr 2009-04-21 16:43:15 +00:00
Родитель 7930673c5d
Коммит 16dc9e04cb
5 изменённых файлов: 27 добавлений и 19 удалений

Просмотреть файл

@ -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.

5
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

Просмотреть файл

@ -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

Просмотреть файл

@ -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))

17
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;