зеркало из https://github.com/github/ruby.git
* lib/date.rb: use subsec instead of nsec.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23377 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
e9e7e62025
Коммит
ad20a9e01a
|
@ -1,3 +1,7 @@
|
|||
Sat May 9 19:23:46 2009 Tadayoshi Funaba <tadf@dotrb.org>
|
||||
|
||||
* lib/date.rb: use subsec instead of nsec.
|
||||
|
||||
Sat May 9 12:19:49 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* hash.c: 3rd arguemnt of rb_hash_foreach() is VALUE.
|
||||
|
|
|
@ -1775,7 +1775,7 @@ class Time
|
|||
def to_datetime
|
||||
jd = DateTime.__send__(:civil_to_jd, year, mon, mday, DateTime::ITALY)
|
||||
fr = DateTime.__send__(:time_to_day_fraction, hour, min, [sec, 59].min) +
|
||||
Rational(nsec, 86400_000_000_000)
|
||||
Rational(subsec, 86400)
|
||||
of = Rational(utc_offset, 86400)
|
||||
DateTime.new!(DateTime.__send__(:jd_to_ajd, jd, fr, of),
|
||||
of, DateTime::ITALY)
|
||||
|
@ -1805,7 +1805,7 @@ class Date
|
|||
t = Time.now
|
||||
jd = civil_to_jd(t.year, t.mon, t.mday, sg)
|
||||
fr = time_to_day_fraction(t.hour, t.min, [t.sec, 59].min) +
|
||||
Rational(t.nsec, 86400_000_000_000)
|
||||
Rational(t.subsec, 86400)
|
||||
of = Rational(t.utc_offset, 86400)
|
||||
new!(jd_to_ajd(jd, fr, of), of, sg)
|
||||
end
|
||||
|
|
|
@ -49,6 +49,13 @@ class TestDateConv < Test::Unit::TestCase
|
|||
assert_equal([2004, 9, 19, 1, 2, 3, 456789123],
|
||||
[t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.nsec])
|
||||
end
|
||||
|
||||
if Time.allocate.respond_to?(:subsec)
|
||||
d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123456789123.to_r/86400000000000000000000
|
||||
t = d.to_time.utc
|
||||
assert_equal([2004, 9, 19, 1, 2, 3, Rational(456789123456789123,1000000000000000000)],
|
||||
[t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.subsec])
|
||||
end
|
||||
end
|
||||
|
||||
def test_to_date__from_time
|
||||
|
|
Загрузка…
Ссылка в новой задаче