Skip to content

Commit

Permalink
* test/date/*.rb: imported additional tests and some adjustments.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19622 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
tadf committed Sep 29, 2008
1 parent 06df404 commit 1ac57f7
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Mon Sep 29 20:22:20 2008 Tadayoshi Funaba <tadf@dotrb.org>

* test/date/*.rb: imported additional tests and some adjustments.

Mon Sep 29 20:13:05 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>

* ext/win32ole/win32ole.c (fev_initialize): initialization
Expand Down
21 changes: 21 additions & 0 deletions test/date/test_date_compat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'test/unit'
require 'date'

class TestDateCompat < Test::Unit::TestCase

def test_compat
assert_equal(DateTime.new, Date.new)
assert_equal(DateTime.new(2002,3,19), Date.new(2002,3,19))
assert_equal(DateTime.new(2002,3,19, 0,0,0), Date.new(2002,3,19))
assert_equal(DateTime.new(2002,3,19, 0,0,0, 0), Date.new(2002,3,19))
assert_equal(DateTime.new(2002,3,19, 0,0,0, 0.to_r), Date.new(2002,3,19))
assert_equal(DateTime.new(2002,3,19, 0,0,0, 0, Date::GREGORIAN), Date.new(2002,3,19, Date::GREGORIAN))
assert_equal(DateTime.new(2002,3,19, 0,0,0, 0, Date::JULIAN), Date.new(2002,3,19, Date::JULIAN))

assert(Date.new(2002,3,19) != DateTime.new(2002,3,19, 12,0,0))
assert(Date.new(2002,3,19) != DateTime.new(2002,3,19, 0,0,1))
assert(Date.new(2002,3,19) === DateTime.new(2002,3,19, 12,0,0))
assert(Date.new(2002,3,19) === DateTime.new(2002,3,19, 0,0,1))
end

end
130 changes: 130 additions & 0 deletions test/date/test_date_conv.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
require 'test/unit'
require 'date'

class TestDateConv < Test::Unit::TestCase

def test_to_class
[Time.now, Date.today, DateTime.now].each do |o|
assert_instance_of(Time, o.to_time)
assert_instance_of(Date, o.to_date)
assert_instance_of(DateTime, o.to_datetime)
end
end

def test_to_time__from_time
t = Time.mktime(2004, 9, 19, 1, 2, 3, 456789)
t2 = t.to_time
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.utc(2004, 9, 19, 1, 2, 3, 456789)
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])
end

def test_to_time__from_date
d = Date.new(2004, 9, 19)
t = d.to_time
assert_equal([2004, 9, 19, 0, 0, 0, 0],
[t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec])
end

def test_to_time__from_datetime
d = DateTime.new(2004, 9, 19, 1, 2, 3, 9.to_r/24) + 456789.to_r/86400000000
t = d.to_time
if t.utc_offset == 9*60*60
assert_equal([2004, 9, 19, 1, 2, 3, 456789],
[t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec])
end

d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789.to_r/86400000000
t = d.to_time.utc
assert_equal([2004, 9, 19, 1, 2, 3, 456789],
[t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec])

if Time.allocate.respond_to?(:nsec)
d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123.to_r/86400000000000
t = d.to_time.utc
assert_equal([2004, 9, 19, 1, 2, 3, 456789123],
[t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.nsec])
end
end

def test_to_date__from_time
t = Time.mktime(2004, 9, 19, 1, 2, 3, 456789)
d = t.to_date
assert_equal([2004, 9, 19, 0], [d.year, d.mon, d.mday, d.day_fraction])

t = Time.utc(2004, 9, 19, 1, 2, 3, 456789)
d = t.to_date
assert_equal([2004, 9, 19, 0], [d.year, d.mon, d.mday, d.day_fraction])
end

def test_to_date__from_date
d = Date.new(2004, 9, 19) + 1.to_r/2
d2 = d.to_date
assert_equal([2004, 9, 19, 1.to_r/2],
[d2.year, d2.mon, d2.mday, d2.day_fraction])
end

def test_to_date__from_datetime
d = DateTime.new(2004, 9, 19, 1, 2, 3, 9.to_r/24) + 456789.to_r/86400000000
d2 = d.to_date
assert_equal([2004, 9, 19, 0], [d2.year, d2.mon, d2.mday, d2.day_fraction])

d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789.to_r/86400000000
d2 = d.to_date
assert_equal([2004, 9, 19, 0], [d2.year, d2.mon, d2.mday, d2.day_fraction])
end

def test_to_datetime__from_time
t = Time.mktime(2004, 9, 19, 1, 2, 3, 456789)
d = t.to_datetime
assert_equal([2004, 9, 19, 1, 2, 3,
456789.to_r/1000000,
t.utc_offset.to_r/86400],
[d.year, d.mon, d.mday, d.hour, d.min, d.sec,
d.sec_fraction, d.offset])

t = Time.utc(2004, 9, 19, 1, 2, 3, 456789)
d = t.to_datetime
assert_equal([2004, 9, 19, 1, 2, 3,
456789.to_r/1000000,
0],
[d.year, d.mon, d.mday, d.hour, d.min, d.sec,
d.sec_fraction, d.offset])

t = Time.now
d = t.to_datetime
require 'time'
assert_equal(t.iso8601(10), d.iso8601(10))
end

def test_to_datetime__from_date
d = Date.new(2004, 9, 19) + 1.to_r/2
d2 = d.to_datetime
assert_equal([2004, 9, 19, 0, 0, 0, 0, 0],
[d2.year, d2.mon, d2.mday, d2.hour, d2.min, d2.sec,
d2.sec_fraction, d2.offset])
end

def test_to_datetime__from_datetime
d = DateTime.new(2004, 9, 19, 1, 2, 3, 9.to_r/24) + 456789.to_r/86400000000
d2 = d.to_datetime
assert_equal([2004, 9, 19, 1, 2, 3,
456789.to_r/1000000,
9.to_r/24],
[d2.year, d2.mon, d2.mday, d2.hour, d2.min, d2.sec,
d2.sec_fraction, d2.offset])

d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789.to_r/86400000000
d2 = d.to_datetime
assert_equal([2004, 9, 19, 1, 2, 3,
456789.to_r/1000000,
0],
[d2.year, d2.mon, d2.mday, d2.hour, d2.min, d2.sec,
d2.sec_fraction, d2.offset])
end

end
1 change: 1 addition & 0 deletions test/date/test_date_parse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ def test__parse

def test__parse_slash_exp
[
# little
[['2/5/1999',false],[1999,5,2,nil,nil,nil,nil,nil,nil]],
[['02/05/1999',false],[1999,5,2,nil,nil,nil,nil,nil,nil]],
[['02/05/-1999',false],[-1999,5,2,nil,nil,nil,nil,nil,nil]],
Expand Down
5 changes: 1 addition & 4 deletions test/date/test_date_strftime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def test__different_format
assert_equal('M45.07.29', Date.parse('1912-07-29').jisx0301)
assert_equal('T01.07.30', Date.parse('1912-07-30').jisx0301)
assert_equal('T15.12.24', Date.parse('1926-12-24').jisx0301)
assert_equal('S01.12.25', Date.parse('1926-12-25').jisx0301)
assert_equal('S01.12.25', Date.parse('1926-12-25').jisx0301)
assert_equal('S64.01.07', Date.parse('1989-01-07').jisx0301)
assert_equal('H01.01.08', Date.parse('1989-01-08').jisx0301)
assert_equal('H18.09.01', Date.parse('2006-09-01').jisx0301)
Expand All @@ -366,9 +366,6 @@ def test__different_format
assert_equal(s, Date.parse(s).jisx0301)
end

d = Date.new(2001,2,3)
d2 = DateTime.new(2001,2,3,2)

end

end

0 comments on commit 1ac57f7

Please sign in to comment.