* lib/time.rb: revert r54167 because it would break

backward compatibilities, and it is documented that
  Time.parse does not take into account time zone
  abbreations other than ones described in RFC 822

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54647 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
sonots 2016-04-19 04:20:48 +00:00
parent b48c212ec9
commit 64231b49ca
3 changed files with 14 additions and 45 deletions

View File

@ -1,3 +1,10 @@
Tue Apr 19 13:18:12 2016 Naotoshi Seo <sonots@gmail.com>
* lib/time.rb: revert r54167 because it would break
backward compatibilities, and it is documented that
Time.parse does not take into account time zone
abbreations other than ones described in RFC 822
Tue Apr 19 13:12:03 2016 Naotoshi Seo <sonots@gmail.com> Tue Apr 19 13:12:03 2016 Naotoshi Seo <sonots@gmail.com>
* ChangeLog: Fix dates of previous commits * ChangeLog: Fix dates of previous commits

View File

@ -249,18 +249,14 @@ class Time
end end
private :apply_offset private :apply_offset
def make_time(date, year, mon, day, hour, min, sec, sec_fraction, zone, offset, now) def make_time(date, year, mon, day, hour, min, sec, sec_fraction, zone, now)
if !year && !mon && !day && !hour && !min && !sec && !sec_fraction if !year && !mon && !day && !hour && !min && !sec && !sec_fraction
raise ArgumentError, "no time information in #{date.inspect}" raise ArgumentError, "no time information in #{date.inspect}"
end end
off_year = year || now.year
off = nil off = nil
if offset off = zone_offset(zone, off_year) if zone
off = offset
else
off_year = year || now.year
off = zone_offset(zone, off_year) if zone
end
if off if off
now = now.getlocal(off) if now.utc_offset != off now = now.getlocal(off) if now.utc_offset != off
@ -291,10 +287,8 @@ class Time
sec ||= 0 sec ||= 0
usec ||= 0 usec ||= 0
off = nil if year != off_year
if offset off = nil
off = offset
elsif year != off_year
off = zone_offset(zone, year) if zone off = zone_offset(zone, year) if zone
end end
@ -369,7 +363,7 @@ class Time
d = Date._parse(date, comp) d = Date._parse(date, comp)
year = d[:year] year = d[:year]
year = yield(year) if year && !comp year = yield(year) if year && !comp
make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], d[:offset], now) make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
end end
# #
@ -447,7 +441,7 @@ class Time
else else
year = d[:year] year = d[:year]
year = yield(year) if year && block_given? year = yield(year) if year && block_given?
t = make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], d[:offset], now) t = make_time(date, year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
end end
t t
end end

View File

@ -429,23 +429,6 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc:
assert_equal(500000, Time.parse("2000-01-01T00:00:00.5+00:00").tv_usec) assert_equal(500000, Time.parse("2000-01-01T00:00:00.5+00:00").tv_usec)
end end
def test_parse_with_zone
t = Time.parse('2000-01-01T00:00:00 CET')
assert_equal(2000, t.year)
assert_equal(1, t.mon)
assert_equal(1, t.day)
assert_equal(0, t.hour)
assert_equal(0, t.min)
assert_equal(0, t.sec)
assert_equal(3600, t.utc_offset)
assert_equal(false, t.utc?)
Time.instance_eval("ZoneOffset").each do |zone, offset|
t = Time.parse("2000-01-01T00:00:00 #{zone}")
assert_equal(offset*3600, t.utc_offset)
end
end
def test_strptime def test_strptime
assert_equal(Time.utc(2005, 8, 28, 06, 54, 20), Time.strptime("28/Aug/2005:06:54:20 +0000", "%d/%b/%Y:%T %z")) assert_equal(Time.utc(2005, 8, 28, 06, 54, 20), Time.strptime("28/Aug/2005:06:54:20 +0000", "%d/%b/%Y:%T %z"))
assert_equal(Time.at(1).localtime, Time.strptime("1", "%s")) assert_equal(Time.at(1).localtime, Time.strptime("1", "%s"))
@ -496,21 +479,6 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc:
assert_equal(0, t.sec) assert_equal(0, t.sec)
assert_equal(0, t.utc_offset) assert_equal(0, t.utc_offset)
assert_equal(true, t.utc?) assert_equal(true, t.utc?)
t = Time.strptime('20010203 CET', '%Y%m%d %z')
assert_equal(2001, t.year)
assert_equal(2, t.mon)
assert_equal(3, t.day)
assert_equal(0, t.hour)
assert_equal(0, t.min)
assert_equal(0, t.sec)
assert_equal(3600, t.utc_offset)
assert_equal(false, t.utc?)
Time.instance_eval("ZoneOffset").each do |zone, offset|
t = Time.strptime("2000-01-01 #{zone}", '%Y-%m-%d %z')
assert_equal(offset*3600, t.utc_offset)
end
end end
def test_nsec def test_nsec