mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
date_core.c: preserve timezone
* ext/date/date_core.c (time_to_time): should preserve timezone info. [ruby-core:74889] [Bug #12271] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
991c159c17
commit
456523e2ed
3 changed files with 24 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Apr 12 20:40:35 2016 Kaneko Yuichiro <spiketeika@gmail.com>
|
||||
|
||||
* ext/date/date_core.c (time_to_time): should preserve timezone
|
||||
info. [ruby-core:74889] [Bug #12271]
|
||||
|
||||
Tue Apr 12 11:51:18 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* compile.c (new_label_body): initialize bit fields, since
|
||||
|
|
|
@ -8406,12 +8406,12 @@ dt_lite_jisx0301(int argc, VALUE *argv, VALUE self)
|
|||
* call-seq:
|
||||
* t.to_time -> time
|
||||
*
|
||||
* Returns a copy of self as local mode.
|
||||
* Returns self.
|
||||
*/
|
||||
static VALUE
|
||||
time_to_time(VALUE self)
|
||||
{
|
||||
return f_getlocal(self);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -3,6 +3,15 @@ require 'test/unit'
|
|||
require 'date'
|
||||
|
||||
class TestDateConv < Test::Unit::TestCase
|
||||
def with_tz(tz)
|
||||
old = ENV["TZ"]
|
||||
begin
|
||||
ENV["TZ"] = tz
|
||||
yield
|
||||
ensure
|
||||
ENV["TZ"] = old
|
||||
end
|
||||
end
|
||||
|
||||
def test_to_class
|
||||
[Time.now, Date.today, DateTime.now].each do |o|
|
||||
|
@ -22,6 +31,14 @@ class TestDateConv < Test::Unit::TestCase
|
|||
t2 = t.to_time.utc
|
||||
assert_equal([2004, 9, 19, 1, 2, 3, 456789],
|
||||
[t2.year, t2.mon, t2.mday, t2.hour, t2.min, t2.sec, t2.usec])
|
||||
|
||||
t = Time.new(2004, 9, 19, 1, 2, 3, '+03:00')
|
||||
with_tz('Asia/Tokyo') do
|
||||
t2 = t.to_time
|
||||
assert_equal([2004, 9, 19, 1, 2, 3],
|
||||
[t2.year, t2.mon, t2.mday, t2.hour, t2.min, t2.sec])
|
||||
assert_equal(3 * 60 * 60, t2.gmt_offset)
|
||||
end
|
||||
end
|
||||
|
||||
def test_to_time__from_date
|
||||
|
|
Loading…
Reference in a new issue