Updated RubySpec source to bdda4113.
[rbx.git] / test / bfts / test_time.rb
blob01b59d4f69fdab7e01a3c742be5f15342e4a4d8a
1 require 'rubicon_testcase'
4 # NOTICE: These tests assume that your local time zone is *not* GMT.
7 class T # ZenTest SKIP
8   attr :orig
9   attr :amt
10   attr :result
11   def initialize(a1, anAmt, a2)
12     @orig = a1
13     @amt = anAmt
14     @result = a2
15   end
16   def to_s
17     @orig.join("-")
18   end
19 end
21 class TestTime < RubiconTestCase
23   ONEDAYSEC = 60 * 60 * 24
25   #
26   # Test month name to month number
27   #
28   @@months = { 
29     'Jan' => 1,
30     'Feb' => 2,
31     'Mar' => 3,
32     'Apr' => 4,
33     'May' => 5,
34     'Jun' => 6,
35     'Jul' => 7,
36     'Aug' => 8,
37     'Sep' => 9,
38     'Oct' => 10,
39     'Nov' => 11,
40     'Dec' => 12
41   }
43   #
44   # A random selection of interesting dates
45   #
46   @@dates = [ 
47     #                   Source  +   amt         ==   dest
48     T.new([1999, 12, 31, 23,59,59], 1,               [2000,  1,  1,  0,0,0]),
49     T.new([2036, 12, 31, 23,59,59], 1,               [2037,  1,  1,  0,0,0]),
50     T.new([2000,  2, 28, 23,59,59], 1,               [2000,  2, 29, 0,0,0]),
51     T.new([1970,  2, 1,   0, 0, 0], ONEDAYSEC,       [1970,  2,  2,  0,0,0]),
52     T.new([2000,  7, 1,   0, 0, 0], 32 * ONEDAYSEC,  [2000,  8,  2,  0,0,0]),
53     T.new([2000,  1, 1,   0, 0, 0], 366 * ONEDAYSEC, [2001,  1,  1,  0,0,0]),
54     T.new([2001,  1, 1,   0, 0, 0], 365 * ONEDAYSEC, [2002,  1,  1,  0,0,0]),
56     T.new([2000,  1, 1,   0, 0, 0], 0,               [2000,  1,  1,  0,0,0]),
57     T.new([2000,  2, 1,   0, 0, 0], 0,               [2000,  2,  1,  0,0,0]),
58     T.new([2000,  3, 1,   0, 0, 0], 0,               [2000,  3,  1,  0,0,0]),
59     T.new([2000,  4, 1,   0, 0, 0], 0,               [2000,  4,  1,  0,0,0]),
60     T.new([2000,  5, 1,   0, 0, 0], 0,               [2000,  5,  1,  0,0,0]),
61     T.new([2000,  6, 1,   0, 0, 0], 0,               [2000,  6,  1,  0,0,0]),
62     T.new([2000,  7, 1,   0, 0, 0], 0,               [2000,  7,  1,  0,0,0]),
63     T.new([2000,  8, 1,   0, 0, 0], 0,               [2000,  8,  1,  0,0,0]),
64     T.new([2000,  9, 1,   0, 0, 0], 0,               [2000,  9,  1,  0,0,0]),
65     T.new([2000, 10, 1,   0, 0, 0], 0,               [2000, 10,  1,  0,0,0]),
66     T.new([2000, 11, 1,   0, 0, 0], 0,               [2000, 11,  1,  0,0,0]),
67     T.new([2000, 12, 1,   0, 0, 0], 0,               [2000, 12,  1,  0,0,0]), 
69     T.new([2001,  1, 1,   0, 0, 0], 0,               [2001,  1,  1,  0,0,0]),
70     T.new([2001,  2, 1,   0, 0, 0], 0,               [2001,  2,  1,  0,0,0]),
71     T.new([2001,  3, 1,   0, 0, 0], 0,               [2001,  3,  1,  0,0,0]),
72     T.new([2001,  4, 1,   0, 0, 0], 0,               [2001,  4,  1,  0,0,0]),
73     T.new([2001,  5, 1,   0, 0, 0], 0,               [2001,  5,  1,  0,0,0]),
74     T.new([2001,  6, 1,   0, 0, 0], 0,               [2001,  6,  1,  0,0,0]),
75     T.new([2001,  7, 1,   0, 0, 0], 0,               [2001,  7,  1,  0,0,0]),
76     T.new([2001,  8, 1,   0, 0, 0], 0,               [2001,  8,  1,  0,0,0]),
77     T.new([2001,  9, 1,   0, 0, 0], 0,               [2001,  9,  1,  0,0,0]),
78     T.new([2001, 10, 1,   0, 0, 0], 0,               [2001, 10,  1,  0,0,0]),
79     T.new([2001, 11, 1,   0, 0, 0], 0,               [2001, 11,  1,  0,0,0]),
80     T.new([2001, 12, 1,   0, 0, 0], 0,               [2001, 12,  1,  0,0,0]),
81   ]
83   def setup
84     @orig_zone = ENV['TZ']
85     ENV['TZ'] = 'PST8PDT'
86     @utc = Time.utc(2001, 2, 3, 4, 5, 6)
87     @loc = Time.local(2001, 2, 3, 4, 5, 6)
88     @zone = @loc.zone
89   end
91   def teardown
92     ENV['TZ'] = @orig_zone
93   end
95   ##
96   # Check a particular date component -- m is the method (day, month, etc)
97   # and i is the index in the date specifications above.
99   def util_check_component(m, i)
100     @@dates.each do |x|
101       assert_equal(x.orig[i],   Time.local(*x.orig).send(m))
102       assert_equal(x.result[i], Time.local(*x.result).send(m))
103       assert_equal(x.orig[i],   Time.gm(*x.orig).send(m))
104       assert_equal(x.result[i], Time.gm(*x.result).send(m))
105     end
106   end
108   def util_class_now(method)
109     min = 0.1
110     max = min * 3.0 # some ruby impls will be SLOOOW
111     t1 = Time.send(method)
112     sleep min
113     t2 = Time.send(method)
114     delta = t2.to_f - t1.to_f
115     assert(delta >= min, "time difference must be at least #{min}")
116     assert(max >= delta, "time difference should not be more than #{max}")
117   end
119   def util_os_specific_epoch
120     if $os == MsWin32 || $os == JRuby then
121       "Thu Jan 01 00:00:00 1970"
122     else
123       "Thu Jan  1 00:00:00 1970"
124     end
125   end
127   ##
128   # If this test is failing, you've got big problems.  Start with Time::at,
129   # Time::utc and Time::local before looking at bugs in any of your other
130   # code.
132   def test_00sanity # ZenTest SKIP
133     assert_equal(Time.at(981173106), Time.utc(2001, 2, 3, 4, 5, 6),
134                  "If this test fails, don't bother debugging anything else.")
135     assert_equal(Time.at(981201906), Time.local(2001, 2, 3, 4, 5, 6),
136                  "If this test fails, don't bother debugging anything else.")
137   end
139   def test_asctime
140     expected = util_os_specific_epoch
141     assert_equal(expected, Time.at(0).gmtime.asctime)
142   end
144   def test_class__load
145     # TODO: raise NotImplementedError, 'Need to write test_class__load'
146   end
148   def test_class_at
149     sec = @loc.to_i
150     assert_equal(0, Time.at(0).to_i)
151     assert_equal(@loc, Time.at(@loc))
152     assert_in_delta(Time.at(sec,1_000_000).to_f, Time.at(sec).to_f, 1.0)
154     # no arguments ==> error
155     assert_raise(ArgumentError) do
156       Time.at
157     end
159     # one integer argument ==> seconds
160     t = Time.at(1_234_567)
161     assert_equal(1_234_567, t.tv_sec)
162     assert_equal(        0, t.tv_usec)
164     # two integer arguments ==> seconds & microseconds
165     t = Time.at(1_234_567, 888_999)
166     assert_equal(1_234_567, t.tv_sec)
167     assert_equal(  888_999, t.tv_usec)
169     # float argument ==> second & rounded microseconds
170     t = Time.at(1_234_567.5)
171     assert_equal(1_234_567, t.tv_sec)
172     assert_equal(  500_000, t.tv_usec)
174     # float + integer arguments ==> rounded seconds & microseconds
175     t = Time.at(1_234_567.5, 300_000)
176     assert_equal(1_234_567, t.tv_sec)
177     assert_equal(  300_000, t.tv_usec)
179     # Time argument
180     t1 = Time.at(1_234_567,  888_999)
181     t2 = Time.at(t1)
182     assert_equal(1_234_567, t2.tv_sec)
183     assert_equal(  888_999, t2.tv_usec)
184   end
186   def test_class_at_utc
187     utc1 = @utc
188     utc2 = Time.at(@utc)
189     assert(utc1.utc?)
190     assert(utc2.utc?)
191     assert_equal(utc1.to_i, utc2.to_i)
192   end
194   def test_class_gm
195     assert_raises(ArgumentError) { Time.gm }
196     assert_not_equal(Time.gm(2000), Time.local(2000))
197     assert_equal(Time.gm(2000), Time.gm(2000,1,1,0,0,0))
198     assert_equal(Time.gm(2000,nil,nil,nil,nil,nil), Time.gm(2000,1,1,0,0,0))
199     assert_raises(ArgumentError) { Time.gm(2000,0) }
200     assert_raises(ArgumentError) { Time.gm(2000,13) }
201     assert_raises(ArgumentError) { Time.gm(2000,1,1,24) }
202     Time.gm(2000,1,1,23)
203     @@months.each do |month, num| 
204       assert_equal(Time.gm(2000,month), Time.gm(2000,num,1,0,0,0))
205       assert_equal(Time.gm(1970,month), Time.gm(1970,num,1,0,0,0))
206       assert_equal(Time.gm(2037,month), Time.gm(2037,num,1,0,0,0))
207     end
208     t = Time.gm(2000,1,1)
209     a = t.to_a
210     assert_equal(Time.gm(*a),t)
211   end
213   def test_class_local
214     assert_raises(ArgumentError) { Time.local }
215     assert_not_equal(Time.gm(2000), Time.local(2000))
216     assert_equal(Time.local(2000), Time.local(2000,1,1,0,0,0))
217     assert_equal(Time.local(2000,nil,nil,nil,nil,nil), Time.local(2000,1,1,0,0,0))
218     assert_raises(ArgumentError) { Time.local(2000,0) }
219     assert_raises(ArgumentError) { Time.local(2000,13) }
220     assert_raises(ArgumentError) { Time.local(2000,1,1,24) }
221     Time.local(2000,1,1,23)
222     @@months.each do |month, num| 
223       assert_equal(Time.local(2000,month), Time.local(2000,num,1,0,0,0))
224       assert_equal(Time.local(1971,month), Time.local(1971,num,1,0,0,0))
225       assert_equal(Time.local(2037,month), Time.local(2037,num,1,0,0,0))
226     end
227     t = Time.local(2000,1,1)
228     a = t.to_a
229     assert_equal(Time.local(*a),t)
230   end
232   def test_class_mktime
233     #
234     # Test insufficient arguments
235     #
236     assert_raises(ArgumentError) { Time.mktime }
237     assert_not_equal(Time.gm(2000), Time.mktime(2000))
238     assert_equal(Time.mktime(2000), Time.mktime(2000,1,1,0,0,0))
239     assert_equal(Time.mktime(2000,nil,nil,nil,nil,nil), Time.mktime(2000,1,1,0,0,0))
240     assert_raises(ArgumentError) { Time.mktime(2000,0) }
241     assert_raises(ArgumentError) { Time.mktime(2000,13) }
242     assert_raises(ArgumentError) { Time.mktime(2000,1,1,24) }
243     Time.mktime(2000,1,1,23)
245     #
246     # Make sure spelled-out month names work
247     #
248     @@months.each do |month, num| 
249       assert_equal(Time.mktime(2000,month), Time.mktime(2000,num,1,0,0,0))
250       assert_equal(Time.mktime(1971,month), Time.mktime(1971,num,1,0,0,0))
251       assert_equal(Time.mktime(2037,month), Time.mktime(2037,num,1,0,0,0))
252     end
253     t = Time.mktime(2000,1,1)
254     a = t.to_a
255     assert_equal(Time.mktime(*a),t)
256   end
258   def test_class_now
259     util_class_now(:now) # Time.now
260   end
262   def test_class_times
263     assert_instance_of(Struct::Tms, Process.times)
264   end
266   def test_class_utc
267     test_class_gm # TODO: refactor to ensure they really are synonyms
268   end
270   def test_clone
271     for taint in [ false, true ]
272       for frozen in [ false, true ]
273         a = @loc.dup
274         a.taint  if taint
275         a.freeze if frozen
276         b = a.clone
278         assert_equal(a, b)
279         assert_not_equal(a.__id__, b.__id__)
280         assert_equal(a.frozen?, b.frozen?)
281         assert_equal(a.tainted?, b.tainted?)
282       end
283     end
284   end
286   def test_ctime
287     expected = util_os_specific_epoch
288     assert_equal(expected, Time.at(0).gmtime.ctime)
289   end
291   def test_day
292     util_check_component(:day, 2)
293   end
295   def test_dst_eh
296     test_isdst # TODO: refactor to test that they really are the same
297   end
299   def test_dump
300     # TODO: raise NotImplementedError, 'Need to write test__dump'
301   end
303   def test_eql_eh
304     t1 = @loc
305     t2 = Time.at(t1)
306     t3 = t1 + 2e-6
307     t4 = t1 + 1
308     assert(t1.eql?(t1))
309     assert(t1.eql?(t2))
310     assert(!t1.eql?(t3))
311     assert(!t1.eql?(t4))
312     assert(t1.eql?(t1.getutc))
313   end
315   def test_getgm
316     # TODO: this only tests local -> gm
317     t1 = @loc
318     loc = Time.at(t1)
319     assert(!t1.gmt?)
320     t2 = t1.getgm
321     assert(!t1.gmt?)
322     assert(t2.gmt?)
323     assert_equal(t1, loc)
324     assert_equal(t1.asctime, loc.asctime)
325     assert_not_equal(t2.asctime, loc.asctime)
326     assert_not_equal(t1.asctime, t2.asctime)
327     assert_equal(t1, t2)
328   end
330   def test_getlocal
331     # TODO: this only tests gm -> local
332     t1 = @utc
333     utc = Time.at(t1)
334     assert(t1.gmt?)
335     t2 = t1.getlocal
336     assert(t1.gmt?)
337     assert(!t2.gmt?)
338     assert_equal(t1, utc)
339     assert_equal(t1.asctime, utc.asctime)
340     assert_not_equal(t2.asctime, utc.asctime)
341     assert_not_equal(t1.asctime, t2.asctime)
342     assert_equal(t1, t2)
343   end
345   def test_getutc
346     test_getgm # REFACTOR to test both calls
347   end
349   def test_gmt_eh
350     assert(!@loc.gmt?)
351     assert(@utc.gmt?)
352     assert(!Time.local(2000).gmt?)
353     assert(Time.gm(2000).gmt?)
354   end
356   def test_gmt_offset
357     test_utc_offset # REFACTOR to test both methods
358   end
360   def test_gmtime
361     # TODO: this only tests local -> gm
362     t = @loc
363     loc = Time.at(t)
364     assert(!t.gmt?)
365     t.gmtime
366     assert(t.gmt?)
367     assert_not_equal(t.asctime, loc.asctime)
368   end
370   def test_gmtoff
371     test_utc_offset # REFACTOR to test both methods
372   end
374   def test_hash
375     t1 = @utc
376     t2 = Time.at(t1)
377     t3 = @utc + 1
378     assert_equal(t1.hash, t2.hash)
379     assert_not_equal(t1.hash, t3.hash)
380   end
382   def test_hour
383     util_check_component(:hour, 3)
384   end
386   def test_initialize
387     util_class_now(:new) # Time.new
388   end
390   def test_inspect
391     assert_equal("Sat Feb 03 04:05:06 UTC 2001", @utc.inspect)
392     assert_equal("Sat Feb 03 04:05:06 #{@zone} 2001", @loc.inspect)
393   end
395   def test_isdst
396     # This code is problematic: how do I find out the exact
397     # date and time of the dst switch for all the possible
398     # timezones in which this code runs? For now, I'll just check
399     # midvalues, and add boundary checks for the US. I know this won't 
400     # work in some parts of the US, even, so I'm looking for
401     # better ideas
403     # Are we in the US?
404     if ["EST", "EDT",
405         "CST", "CDT",
406         "MST", "MDT",
407         "PST", "PDT"].include? @zone
409       dtest = [ 
410         [false, 2000, 1, 1],
411         [true,  2000, 7, 1],
412         [true,  2000, 4, 2, 4],
413         [false, 2000, 10, 29, 4],
414         [false, 2000, 4,2,1,59],   # Spring forward
415         [true,  2000, 4,2,3,0],
416         [true,  2000, 10,29,0,59], # Fall back
417         [false, 2000, 10,29,2,0]
418       ]
420       dtest.each do |x|
421         result = x.shift
422         assert_equal(result, Time.local(*x).isdst,
423                      "\nExpected Time.local(#{x.join(',')}).isdst == #{result}")
424       end
425     else
426       skipping("Don't know how to do timezones");
427     end
428   end
430   def test_localtime
431     # TODO: this only tests gm -> local
432     t = @utc
433     utc = Time.at(t)
434     assert(t.gmt?)
435     t.localtime
436     assert(!t.gmt?)
437     assert_not_equal(t.asctime, utc.asctime)
438   end
440   def test_mday
441     util_check_component(:mday, 2)
442   end
444   def test_min
445     util_check_component(:min, 4)
446   end
448   def test_minus # '-'
449     @@dates.each do |x|
450       # Check subtracting an amount in seconds
451       assert_equal(Time.local(*x.result) - x.amt, Time.local(*x.orig))
452       assert_equal(Time.gm(*x.result) - x.amt, Time.gm(*x.orig))
453       # Check subtracting two times
454       assert_equal(Time.local(*x.result) - Time.local(*x.orig), x.amt)
455       assert_equal(Time.gm(*x.result) - Time.gm(*x.orig), x.amt)
456     end
458     # integer argument
459     t1 = Time.at(1_234_567, 500_000)
460     t2 = t1 - 567
461     assert_equal( 1_234_000, t2.tv_sec)
462     assert_equal(   500_000, t2.tv_usec)
464     # float argument with fractional part
465     t1 = Time.at(1_234_567, 500_000)
466     t2 = t1 - 566.75
467     assert_equal( 1_234_000, t2.tv_sec)
468     assert_equal(   750_000, t2.tv_usec)
470     # Time argument
471     t1 = Time.at(1_234_000, 750_000)
472     t2 = Time.at(1_234_567, 500_000)
473     diff = t2 - t1
474     assert_equal( 566.75, diff)
475   end
477   def test_mon
478     util_check_component(:mon, 1)
479   end
481   def test_month
482     util_check_component(:month, 1)
483   end
485   def test_plus # '+'
486     @@dates.each do |x|
487       assert_equal(Time.local(*x.orig) + x.amt, Time.local(*x.result))
488       assert_equal(Time.gm(*x.orig) + x.amt, Time.gm(*x.result))
489     end
491     # integer argument
492     t1 = Time.at(1_234_567, 500_000)
493     t2 = t1 + 433
494     assert_equal( 1_235_000, t2.tv_sec)
495     assert_equal(   500_000, t2.tv_usec)
497     # float argument with fractional part
498     t1 = Time.at(1_234_567, 500_000)
499     t2 = t1 + 433.25
500     assert_equal( 1_235_000, t2.tv_sec)
501     assert_equal(   750_000, t2.tv_usec)
502   end
504   def test_sec
505     util_check_component(:sec, 5)
506   end
508   def test_spaceship # '<=>'
509     @@dates.each do |x|
510       if (x.amt != 0)
511         assert_equal(1, Time.local(*x.result) <=> Time.local(*x.orig),
512                      "#{x.result} should be > #{x.orig}")
514         assert_equal(-1, Time.local(*x.orig) <=> Time.local(*x.result))
515         assert_equal(0, Time.local(*x.orig) <=> Time.local(*x.orig))
516         assert_equal(0, Time.local(*x.result) <=> Time.local(*x.result))
517         
518         assert_equal(1,Time.gm(*x.result) <=> Time.gm(*x.orig))
519         assert_equal(-1,Time.gm(*x.orig) <=> Time.gm(*x.result))
520         assert_equal(0,Time.gm(*x.orig) <=> Time.gm(*x.orig))
521         assert_equal(0,Time.gm(*x.result) <=> Time.gm(*x.result))
522       end
523     end
525     # microsecond diffs
526     assert_equal( 1, Time.at(10_000, 500_000) <=> Time.at(10_000, 499_999))
527     assert_equal( 0, Time.at(10_000, 500_000) <=> Time.at(10_000, 500_000))
528     assert_equal(-1, Time.at(10_000, 500_000) <=> Time.at(10_000, 500_001))
530     # second diff & microsecond diffs
531     assert_equal(-1, Time.at(10_000, 500_000) <=> Time.at(10_001, 499_999))
532     assert_equal(-1, Time.at(10_000, 500_000) <=> Time.at(10_001, 500_000))
533     assert_equal(-1, Time.at(10_000, 500_000) <=> Time.at(10_001, 500_001))
535     # non-Time object gives nil
536     assert_nil(Time.at(10_000) <=> Object.new)
537   end
539   def test_strftime
540     # Sat Jan  1 14:58:42 2000
541     t = Time.local(2000,1,1,14,58,42)
543     stest = {
544        '%a' => 'Sat',
545        '%A' => 'Saturday',
546        '%b' => 'Jan',
547        '%B' => 'January',
548        #'%c',  The preferred local date and time representation,
549        '%d' => '01',
550        '%H' => '14',
551        '%I' => '02',
552        '%j' => '001',
553        '%m' => '01',
554        '%M' => '58',
555        '%p' => 'PM',
556        '%S' => '42',
557        '%U' => '00',
558        '%W' => '00',
559        '%w' => '6',
560        #'%x',  Preferred representation for the date alone, no time\\
561        #'%X',  Preferred representation for the time alone, no date\\
562        '%y' =>  '00',
563        '%Y' =>  '2000',
564        #'%Z',  Time zone name\\
565        '%%' =>  '%',
566       }
568     stest.each {|flag,val|
569       assert_equal("Got "+val,t.strftime("Got " + flag))
570     }
572   end
574   def test_succ
575     t1 = @loc
576     t2 = t1 + 1
577     t3 = t1.succ
578     assert_equal(t2, t3)
579   end
581   def test_to_a
582     t = @loc
583     a = t.to_a
584     assert_equal(t.sec,  a[0])
585     assert_equal(t.min,  a[1])
586     assert_equal(t.hour, a[2])
587     assert_equal(t.day,  a[3])
588     assert_equal(t.month,a[4])
589     assert_equal(t.year, a[5])
590     assert_equal(t.wday, a[6])
591     assert_equal(t.yday, a[7])
592     assert_equal(t.isdst,a[8])
593     assert_equal(t.zone, a[9])
594   end
596   def test_to_f
597     t = Time.at(10000,1066)
598     assert_in_delta(10000.001066, t.to_f, 1e-7)
599   end
601   def test_to_i
602     t = Time.at(0)
603     assert_equal(0, t.to_i)
604     t = Time.at(10000)
605     assert_equal(10000, t.to_i)
606   end
608   def test_to_s
609     assert_equal("Sat Feb 03 04:05:06 UTC 2001", @utc.to_s)
610     assert_equal("Sat Feb 03 04:05:06 #{@zone} 2001", @loc.to_s)
611   end
613   def test_tv_sec
614     t = Time.at(0)
615     assert_equal(0,t.tv_sec)
616     t = Time.at(10000)
617     assert_equal(10000,t.tv_sec)
618   end
620   def util_usec(s, u, method)
621     t = Time.at(s,u)
622     assert_equal(u,t.send(method))
623   end
625   def test_tv_usec
626     util_usec(10000, 1066, :tv_usec)
627     util_usec(10000, 0, :tv_usec)
628   end
630   def test_usec
631     util_usec(10000, 1066, :usec)
632     util_usec(10000, 0, :usec)
633   end
635   def test_utc
636     test_gmtime # REFACTOR to test both methods
637   end
639   def test_utc_eh
640     test_gmt_eh # REFACTOR to test both methods
641   end
643   def test_utc_offset
644     # TODO: figure out the year, month, & day edgecase setups
645     off = @utc - @loc
646     assert_equal(0, @utc.utc_offset)
647     assert_equal(off, @loc.utc_offset)
648   end
650   def test_wday
651     t = Time.local(2001, 4, 1)
653     7.times { |i|
654       assert_equal(i,t.wday)
655       t += ONEDAYSEC
656     }
657   end
659   def test_yday
660     # non-leap 1/1, 2/28,       3/1, 12/31
661     #     leap 1/1, 2/28, 2/29, 3/1, 12/31
662     # leap century (2000)
663     # want to do a non-leap century, but they are out of range.
664     # any others?
666     # non-leap year:
667     assert_equal(  1, Time.local(1999,  1,  1).yday)
668     assert_equal( 59, Time.local(1999,  2, 28).yday)
669     assert_equal( 60, Time.local(1999,  3,  1).yday)
670     assert_equal(365, Time.local(1999, 12, 31).yday)
672     # leap century:
673     assert_equal(  1, Time.local(2000,  1,  1).yday)
674     assert_equal( 59, Time.local(2000,  2, 28).yday)
675     assert_equal( 60, Time.local(2000,  2, 29).yday)
676     assert_equal( 61, Time.local(2000,  3,  1).yday)
677     assert_equal(366, Time.local(2000, 12, 31).yday)
679     # leap year:
680     assert_equal(  1, Time.local(2004,  1,  1).yday)
681     assert_equal( 59, Time.local(2004,  2, 28).yday)
682     assert_equal( 60, Time.local(2004,  2, 29).yday)
683     assert_equal( 61, Time.local(2004,  3,  1).yday)
684     assert_equal(366, Time.local(2004, 12, 31).yday)
685   end
687   def test_year
688     util_check_component(:year, 0)
689   end
691   def test_zone
692     gmt = "UTC"
693     t = @utc
694     assert_equal(gmt, t.zone)
695     t = @loc
696     assert_not_equal(gmt, t.zone)
697   end