1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/time.rb (Time.make_time): Adjust the time zone of "now".

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45843 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-05-06 09:50:08 +00:00
parent d85c226f73
commit e4b05d91eb
3 changed files with 27 additions and 2 deletions

View file

@ -1,3 +1,7 @@
Tue May 6 18:48:50 2014 Tanaka Akira <akr@fsij.org>
* lib/time.rb (Time.make_time): Adjust the time zone of "now".
Tue May 6 18:33:12 2014 Tadayoshi Funaba <tadf@dotrb.org>
* io.c (io_{read,write}_nonblock): use rb_get_kwargs instead of

View file

@ -251,8 +251,19 @@ class Time
raise ArgumentError, "no time information in #{date.inspect}"
end
off_year = year || now.year
off = nil
off = zone_offset(zone, off_year) if zone
if off
now = now.getlocal(off) if now.utc_offset != off
else
now = now.getlocal
end
usec = nil
usec = sec_fraction * 1000000 if sec_fraction
if now
begin
break if year; year = now.year
@ -273,8 +284,10 @@ class Time
sec ||= 0
usec ||= 0
off = nil
off = zone_offset(zone, year) if zone
if year != off_year
off = nil
off = zone_offset(zone, year) if zone
end
if off
year, mon, day, hour, min, sec =

View file

@ -238,6 +238,14 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc:
assert_raise(ArgumentError) { Time.parse("foo", now) }
end
def test_completion_with_different_timezone
now = Time.new(2001,2,3,0,0,0,"+09:00") # 2001-02-02 15:00:00 UTC
t = Time.parse("10:20:30 GMT", now)
assert_equal(Time.utc(2001,2,2,10,20,30), t)
assert_equal(false, t.utc?)
assert_equal(0, t.utc_offset)
end
def test_invalid
# They were actually used in some web sites.
assert_raise(ArgumentError) { Time.httpdate("1 Dec 2001 10:23:57 GMT") }