2004-01-17 23:00:00 -05:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
class TestTime < Test::Unit::TestCase
|
|
|
|
def test_time_add()
|
|
|
|
assert_equal(Time.utc(2000, 3, 21, 3, 30) + 3 * 3600,
|
|
|
|
Time.utc(2000, 3, 21, 6, 30))
|
|
|
|
assert_equal(Time.utc(2000, 3, 21, 3, 30) + (-3 * 3600),
|
|
|
|
Time.utc(2000, 3, 21, 0, 30))
|
2004-01-19 02:32:47 -05:00
|
|
|
assert_equal(0, (Time.at(1.1) + 0.9).usec)
|
2004-01-17 23:00:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_time_subt()
|
|
|
|
assert_equal(Time.utc(2000, 3, 21, 3, 30) - 3 * 3600,
|
|
|
|
Time.utc(2000, 3, 21, 0, 30))
|
|
|
|
assert_equal(Time.utc(2000, 3, 21, 3, 30) - (-3 * 3600),
|
|
|
|
Time.utc(2000, 3, 21, 6, 30))
|
2004-01-19 02:32:47 -05:00
|
|
|
assert_equal(900000, (Time.at(1.1) - 0.2).usec)
|
2004-01-17 23:00:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_time_time()
|
|
|
|
assert_equal(Time.utc(2000, 3, 21, 3, 30) \
|
|
|
|
-Time.utc(2000, 3, 21, 0, 30), 3*3600)
|
|
|
|
assert_equal(Time.utc(2000, 3, 21, 0, 30) \
|
|
|
|
-Time.utc(2000, 3, 21, 3, 30), -3*3600)
|
|
|
|
end
|
2004-03-30 06:31:44 -05:00
|
|
|
|
|
|
|
def test_negative
|
|
|
|
begin
|
|
|
|
Time.at(-1)
|
|
|
|
rescue ArgumentError
|
|
|
|
return
|
|
|
|
end
|
|
|
|
assert_equal(-1, Time.utc(1969, 12, 31, 23, 59, 59).tv_sec)
|
|
|
|
assert_equal(-2, Time.utc(1969, 12, 31, 23, 59, 58).tv_sec)
|
|
|
|
end
|
2004-01-17 23:00:00 -05:00
|
|
|
end
|