summaryrefslogtreecommitdiffhomepage
path: root/test/test_time.rb
blob: ea6e98696812fec65eb93f5705ad184e71289808 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
$ok     = 0
$failed = 0
$ftest  = []

def assert(str = "Assertion failed")
    if(!yield)
      $ftest.push(str)
      $failed += 1
      print "F"
    else
      $ok     += 1
      print "."
    end
end

def report()
  print "\n"
  $ftest.each do |str|
    puts("Test Failed: #{str}");
  end
  $total = $ok + $failed
  puts "Ran #{$total} tests: #{$ok} OK and #{$failed} failed."
end

doom = Time.gm(2012, 12, 23)
assert("Time.gm")   { doom                      }
assert("gm year")   { doom.year == 2012         }
assert("gm month")  { doom.month == 12          }
assert("gm day")    { doom.mday == 23           }

t0 = Time.new
assert("Can create time.") { t0 }

t1 = Time.at(1300000000.0).utc
assert("asctime") { t1.asctime == "Sun Mar 13 07:06:40 UTC 2011" }
assert("usec")    { t1.usec    ==  0              }
assert("to_i")    { t1.to_i    ==  1300000000     }
assert("to_f")    { t1.to_f    ==  1300000000.0   }
assert("utc?")    { t1.utc?                       }
assert("zone")    { t1.zone    == "UTC"           }
assert("wday")    { t1.wday    ==  0              }
assert("yday")    { t1.yday    ==  71             }
assert("year")    { t1.year    ==  2011           }

t2 = Time.at(7.0e6)
assert("initialize_copy") { t2.clone == t2 }

report()