tzinfo 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of tzinfo might be problematic. Click here for more details.

Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.yardopts +6 -0
  5. data/{CHANGES → CHANGES.md} +121 -50
  6. data/{README → README.md} +48 -34
  7. data/Rakefile +45 -22
  8. data/lib/tzinfo.rb +7 -2
  9. data/lib/tzinfo/country.rb +23 -1
  10. data/lib/tzinfo/country_index_definition.rb +6 -1
  11. data/lib/tzinfo/country_timezone.rb +9 -1
  12. data/lib/tzinfo/data_source.rb +26 -5
  13. data/lib/tzinfo/data_timezone.rb +30 -2
  14. data/lib/tzinfo/data_timezone_info.rb +26 -0
  15. data/lib/tzinfo/info_timezone.rb +3 -1
  16. data/lib/tzinfo/linked_timezone.rb +30 -1
  17. data/lib/tzinfo/offset_rationals.rb +5 -3
  18. data/lib/tzinfo/ruby_core_support.rb +2 -0
  19. data/lib/tzinfo/ruby_country_info.rb +14 -0
  20. data/lib/tzinfo/ruby_data_source.rb +5 -0
  21. data/lib/tzinfo/time_or_datetime.rb +16 -1
  22. data/lib/tzinfo/timezone.rb +107 -5
  23. data/lib/tzinfo/timezone_definition.rb +5 -1
  24. data/lib/tzinfo/timezone_index_definition.rb +7 -1
  25. data/lib/tzinfo/{timezone_offset_info.rb → timezone_offset.rb} +12 -10
  26. data/lib/tzinfo/timezone_period.rb +19 -15
  27. data/lib/tzinfo/timezone_proxy.rb +5 -1
  28. data/lib/tzinfo/timezone_transition.rb +136 -0
  29. data/lib/tzinfo/{timezone_transition_info.rb → timezone_transition_definition.rb} +21 -57
  30. data/lib/tzinfo/transition_data_timezone_info.rb +81 -8
  31. data/lib/tzinfo/zoneinfo_country_info.rb +7 -0
  32. data/lib/tzinfo/zoneinfo_data_source.rb +104 -57
  33. data/lib/tzinfo/zoneinfo_timezone_info.rb +18 -10
  34. data/test/tc_country.rb +39 -1
  35. data/test/tc_data_timezone.rb +28 -5
  36. data/test/tc_linked_timezone.rb +24 -3
  37. data/test/tc_ruby_data_source.rb +22 -2
  38. data/test/tc_time_or_datetime.rb +3 -3
  39. data/test/tc_timezone.rb +364 -117
  40. data/test/tc_timezone_london.rb +25 -0
  41. data/test/tc_timezone_melbourne.rb +24 -0
  42. data/test/tc_timezone_new_york.rb +24 -0
  43. data/test/{tc_timezone_offset_info.rb → tc_timezone_offset.rb} +27 -27
  44. data/test/tc_timezone_period.rb +113 -90
  45. data/test/tc_timezone_transition.rb +374 -0
  46. data/test/tc_timezone_transition_definition.rb +306 -0
  47. data/test/tc_transition_data_timezone_info.rb +143 -43
  48. data/test/tc_zoneinfo_data_source.rb +69 -5
  49. data/test/tc_zoneinfo_timezone_info.rb +63 -20
  50. data/test/test_utils.rb +27 -7
  51. data/tzinfo.gemspec +21 -0
  52. metadata +61 -38
  53. metadata.gz.sig +3 -0
  54. data/test/tc_timezone_transition_info.rb +0 -471
  55. data/test/zoneinfo/UTC +0 -0
  56. data/test/zoneinfo/localtime +0 -0
@@ -78,7 +78,17 @@ class TCRubyDataSource < Test::Unit::TestCase
78
78
 
79
79
  def test_load_timezone_info_tainted
80
80
  safe_test do
81
- info = @data_source.load_timezone_info('Europe/Amsterdam'.taint)
81
+ identifier = 'Europe/Amsterdam'.taint
82
+ assert(identifier.tainted?)
83
+ info = @data_source.load_timezone_info(identifier)
84
+ assert_equal('Europe/Amsterdam', info.identifier)
85
+ assert(identifier.tainted?)
86
+ end
87
+ end
88
+
89
+ def test_load_timezone_info_tainted_and_frozen
90
+ safe_test do
91
+ info = @data_source.load_timezone_info('Europe/Amsterdam'.taint.freeze)
82
92
  assert_equal('Europe/Amsterdam', info.identifier)
83
93
  end
84
94
  end
@@ -132,7 +142,17 @@ class TCRubyDataSource < Test::Unit::TestCase
132
142
 
133
143
  def test_load_country_info_tainted
134
144
  safe_test do
135
- info = @data_source.load_country_info('NL'.taint)
145
+ code = 'NL'.taint
146
+ assert(code.tainted?)
147
+ info = @data_source.load_country_info(code)
148
+ assert_equal('NL', info.code)
149
+ assert(code.tainted?)
150
+ end
151
+ end
152
+
153
+ def test_load_country_info_tainted_and_frozen
154
+ safe_test do
155
+ info = @data_source.load_country_info('NL'.taint.freeze)
136
156
  assert_equal('NL', info.code)
137
157
  end
138
158
  end
@@ -36,14 +36,14 @@ class TCTimeOrDateTime < Test::Unit::TestCase
36
36
  tdt = TimeOrDateTime.new(Time.local(2006, 3, 24, 15, 32, 3))
37
37
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), tdt.to_time)
38
38
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), tdt.to_orig)
39
- assert_equal('UTC', tdt.to_time.zone)
39
+ assert(tdt.to_time.utc?)
40
40
  end
41
41
 
42
42
  def test_intialize_time_local_usec
43
43
  tdt = TimeOrDateTime.new(Time.local(2006, 3, 24, 15, 32, 3, 721123))
44
44
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123), tdt.to_time)
45
45
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123), tdt.to_orig)
46
- assert_equal('UTC', tdt.to_time.zone)
46
+ assert(tdt.to_time.utc?)
47
47
  end
48
48
 
49
49
  if Time.utc(2013, 1, 1).respond_to?(:nsec)
@@ -51,7 +51,7 @@ class TCTimeOrDateTime < Test::Unit::TestCase
51
51
  tdt = TimeOrDateTime.new(Time.local(2006, 3, 24, 15, 32, 3, 721123 + Rational(456,1000)))
52
52
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123 + Rational(456,1000)), tdt.to_time)
53
53
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123 + Rational(456,1000)), tdt.to_orig)
54
- assert_equal('UTC', tdt.to_time.zone)
54
+ assert(tdt.to_time.utc?)
55
55
  end
56
56
  end
57
57
 
data/test/tc_timezone.rb CHANGED
@@ -52,6 +52,10 @@ class TCTimezone < Test::Unit::TestCase
52
52
  @periods_for_local.clone
53
53
  end
54
54
 
55
+ def transitions_up_to(utc_to, utc_from = nil)
56
+ raise 'transitions_up_to called'
57
+ end
58
+
55
59
  private
56
60
  def setup(identifier, period_for_utc, periods_for_local, expected)
57
61
  @identifier = identifier
@@ -61,10 +65,112 @@ class TCTimezone < Test::Unit::TestCase
61
65
  end
62
66
  end
63
67
 
68
+ class OffsetsUpToTestTimezone < Timezone
69
+ def self.new(identifier, expected_utc_to, expected_utc_from, transitions_up_to)
70
+ t = super()
71
+ t.send(:setup, identifier, expected_utc_to, expected_utc_from, transitions_up_to)
72
+ t
73
+ end
74
+
75
+ def identifier
76
+ @identifier
77
+ end
78
+
79
+ def period_for_utc(utc)
80
+ raise 'period_for_utc called'
81
+ end
82
+
83
+ def periods_for_local(local)
84
+ raise 'periods_for_local called'
85
+ end
86
+
87
+ def transitions_up_to(utc_to, utc_from = nil)
88
+ utc_to = TimeOrDateTime.wrap(utc_to)
89
+ raise "Unexpected utc_to #{utc_to || 'nil'} in transitions_up_to" unless @expected_utc_to.eql?(utc_to)
90
+
91
+ utc_from = utc_from ? TimeOrDateTime.wrap(utc_from) : nil
92
+ raise "Unexpected utc_from #{utc_from || 'nil'} in transitions_up_to" unless @expected_utc_from.eql?(utc_from)
93
+
94
+ if utc_from && utc_to <= utc_from
95
+ raise ArgumentError, 'utc_to must be greater than utc_from'
96
+ end
97
+
98
+ @transitions_up_to
99
+ end
100
+
101
+ private
102
+
103
+ def setup(identifier, expected_utc_to, expected_utc_from, transitions_up_to)
104
+ @identifier = identifier
105
+ @expected_utc_to = TimeOrDateTime.wrap(expected_utc_to)
106
+ @expected_utc_from = expected_utc_from ? TimeOrDateTime.wrap(expected_utc_from) : nil
107
+ @transitions_up_to = transitions_up_to
108
+ end
109
+ end
110
+
111
+ class OffsetsUpToNoTransitionsTestTimezone < Timezone
112
+ def self.new(identifier, expected_utc_to, expected_utc_from, period_for_utc)
113
+ t = super()
114
+ t.send(:setup, identifier, expected_utc_to, expected_utc_from, period_for_utc)
115
+ t
116
+ end
117
+
118
+ def identifier
119
+ @identifier
120
+ end
121
+
122
+ def period_for_utc(utc)
123
+ utc = TimeOrDateTime.wrap(utc)
124
+
125
+ raise "Unexpected utc #{utc} in period_for_utc (should be utc_from)" if @expected_utc_from && !@expected_utc_from.eql?(utc)
126
+ raise "Unexpected utc #{utc} in period_for_utc (should be < utc_to)" if !@expected_utc_from && @expected_utc_to <= utc
127
+
128
+ @period_for_utc
129
+ end
130
+
131
+ def periods_for_local(local)
132
+ raise 'periods_for_local called'
133
+ end
134
+
135
+ def transitions_up_to(utc_to, utc_from = nil)
136
+ utc_to = TimeOrDateTime.wrap(utc_to)
137
+ raise "Unexpected utc_to #{utc_to || 'nil'} in transitions_up_to" unless @expected_utc_to.eql?(utc_to)
138
+
139
+ utc_from = utc_from ? TimeOrDateTime.wrap(utc_from) : nil
140
+ raise "Unexpected utc_from #{utc_from || 'nil'} in transitions_up_to" unless @expected_utc_from.eql?(utc_from)
141
+
142
+ if utc_from && utc_to <= utc_from
143
+ raise ArgumentError, 'utc_to must be greater than utc_from'
144
+ end
145
+
146
+ []
147
+ end
148
+
149
+ private
150
+
151
+ def setup(identifier, expected_utc_to, expected_utc_from, period_for_utc)
152
+ @identifier = identifier
153
+ @expected_utc_to = TimeOrDateTime.wrap(expected_utc_to)
154
+ @expected_utc_from = expected_utc_from ? TimeOrDateTime.wrap(expected_utc_from) : nil
155
+ @period_for_utc = period_for_utc
156
+ end
157
+ end
158
+
159
+ class TestTimezoneTransition < TimezoneTransition
160
+ def initialize(offset, previous_offset, at)
161
+ super(offset, previous_offset)
162
+ @at = TimeOrDateTime.wrap(at)
163
+ end
164
+
165
+ def at
166
+ @at
167
+ end
168
+ end
169
+
64
170
  def setup
65
171
  @orig_default_dst = Timezone.default_dst
66
172
  @orig_data_source = DataSource.get
67
- Timezone.send :class_variable_set, :@@loaded_zones, {}
173
+ Timezone.send :init_loaded_zones
68
174
  end
69
175
 
70
176
  def teardown
@@ -159,14 +265,36 @@ class TCTimezone < Test::Unit::TestCase
159
265
  Timezone.get('Europe/Andorra')
160
266
 
161
267
  safe_test do
162
- tz = Timezone.get('Europe/Andorra'.taint)
268
+ identifier = 'Europe/Andorra'.taint
269
+ assert(identifier.tainted?)
270
+ tz = Timezone.get(identifier)
271
+ assert_equal('Europe/Andorra', tz.identifier)
272
+ assert(identifier.tainted?)
273
+ end
274
+ end
275
+
276
+ def test_get_tainted_and_frozen_loaded
277
+ Timezone.get('Europe/Andorra')
278
+
279
+ safe_test do
280
+ tz = Timezone.get('Europe/Andorra'.taint.freeze)
163
281
  assert_equal('Europe/Andorra', tz.identifier)
164
282
  end
165
283
  end
166
284
 
167
285
  def test_get_tainted_not_previously_loaded
168
286
  safe_test do
169
- tz = Timezone.get('Europe/Amsterdam'.taint)
287
+ identifier = 'Europe/Andorra'.taint
288
+ assert(identifier.tainted?)
289
+ tz = Timezone.get(identifier)
290
+ assert_equal('Europe/Andorra', tz.identifier)
291
+ assert(identifier.tainted?)
292
+ end
293
+ end
294
+
295
+ def test_get_tainted_and_frozen_not_previously_loaded
296
+ safe_test do
297
+ tz = Timezone.get('Europe/Amsterdam'.taint.freeze)
170
298
  assert_equal('Europe/Amsterdam', tz.identifier)
171
299
  end
172
300
  end
@@ -182,7 +310,8 @@ class TCTimezone < Test::Unit::TestCase
182
310
  assert_raises(UnknownTimezone) { tz.periods_for_local(DateTime.new(2006,1,1,1,0,0)) }
183
311
  assert_raises(UnknownTimezone) { tz.period_for_local(DateTime.new(2006,1,1,1,0,0)) }
184
312
  assert_raises(UnknownTimezone) { tz.now }
185
- assert_raises(UnknownTimezone) { tz.current_period_and_time }
313
+ assert_raises(UnknownTimezone) { tz.current_period_and_time }
314
+ assert_raises(UnknownTimezone) { tz.transitions_up_to(DateTime.new(2006,1,1,1,0,0)) }
186
315
  end
187
316
 
188
317
  def test_new_nil
@@ -196,7 +325,8 @@ class TCTimezone < Test::Unit::TestCase
196
325
  assert_raises(UnknownTimezone) { tz.periods_for_local(DateTime.new(2006,1,1,1,0,0)) }
197
326
  assert_raises(UnknownTimezone) { tz.period_for_local(DateTime.new(2006,1,1,1,0,0)) }
198
327
  assert_raises(UnknownTimezone) { tz.now }
199
- assert_raises(UnknownTimezone) { tz.current_period_and_time }
328
+ assert_raises(UnknownTimezone) { tz.current_period_and_time }
329
+ assert_raises(UnknownTimezone) { tz.transitions_up_to(DateTime.new(2006,1,1,1,0,0)) }
200
330
  end
201
331
 
202
332
  def test_new_arg
@@ -342,12 +472,12 @@ class TCTimezone < Test::Unit::TestCase
342
472
  t3 = Time.utc(2005,2,18,16,24,23,789000)
343
473
  ts = t.to_i
344
474
 
345
- o1 = TimezoneOffsetInfo.new(0, 0, :GMT)
346
- o2 = TimezoneOffsetInfo.new(0, 3600, :BST)
475
+ o1 = TimezoneOffset.new(0, 0, :GMT)
476
+ o2 = TimezoneOffset.new(0, 3600, :BST)
347
477
 
348
478
  period = TimezonePeriod.new(
349
- TimezoneTransitionInfo.new(o1, o2, 1099184400),
350
- TimezoneTransitionInfo.new(o2, o1, 1111885200))
479
+ TestTimezoneTransition.new(o1, o2, 1099184400),
480
+ TestTimezoneTransition.new(o2, o1, 1111885200))
351
481
 
352
482
  dt_period = TestTimezone.new('Europe/London', nil, [period], dt).period_for_local(dt)
353
483
  dt2_period = TestTimezone.new('Europe/London', nil, [period], dt2).period_for_local(dt2)
@@ -375,12 +505,12 @@ class TCTimezone < Test::Unit::TestCase
375
505
  end
376
506
 
377
507
  def test_period_for_local_ambiguous
378
- o1 = TimezoneOffsetInfo.new(-18000, 0, :EST)
379
- o2 = TimezoneOffsetInfo.new(-18000, 3600, :EDT)
508
+ o1 = TimezoneOffset.new(-18000, 0, :EST)
509
+ o2 = TimezoneOffset.new(-18000, 3600, :EDT)
380
510
 
381
- t1 = TimezoneTransitionInfo.new(o2, o1, 1081062000)
382
- t2 = TimezoneTransitionInfo.new(o1, o2, 1099202400)
383
- t3 = TimezoneTransitionInfo.new(o2, o1, 1112511600)
511
+ t1 = TestTimezoneTransition.new(o2, o1, 1081062000)
512
+ t2 = TestTimezoneTransition.new(o1, o2, 1099202400)
513
+ t3 = TestTimezoneTransition.new(o2, o1, 1112511600)
384
514
 
385
515
  p1 = TimezonePeriod.new(t1, t2)
386
516
  p2 = TimezonePeriod.new(t2, t3)
@@ -405,12 +535,12 @@ class TCTimezone < Test::Unit::TestCase
405
535
  end
406
536
 
407
537
  def test_period_for_local_not_found
408
- o1 = TimezoneOffsetInfo.new(-18000, 0, :EST)
409
- o2 = TimezoneOffsetInfo.new(-18000, 3600, :EDT)
538
+ o1 = TimezoneOffset.new(-18000, 0, :EST)
539
+ o2 = TimezoneOffset.new(-18000, 3600, :EDT)
410
540
 
411
- t1 = TimezoneTransitionInfo.new(o1, o2, 1067148000)
412
- t2 = TimezoneTransitionInfo.new(o2, o1, 1081062000)
413
- t3 = TimezoneTransitionInfo.new(o1, o2, 1099202400)
541
+ t1 = TestTimezoneTransition.new(o1, o2, 1067148000)
542
+ t2 = TestTimezoneTransition.new(o2, o1, 1081062000)
543
+ t3 = TestTimezoneTransition.new(o1, o2, 1099202400)
414
544
 
415
545
  p1 = TimezonePeriod.new(t1, t2)
416
546
  p2 = TimezonePeriod.new(t2, t3)
@@ -437,12 +567,12 @@ class TCTimezone < Test::Unit::TestCase
437
567
  def test_period_for_local_default_dst_set_true
438
568
  Timezone.default_dst = true
439
569
 
440
- o1 = TimezoneOffsetInfo.new(-18000, 0, :EST)
441
- o2 = TimezoneOffsetInfo.new(-18000, 3600, :EDT)
570
+ o1 = TimezoneOffset.new(-18000, 0, :EST)
571
+ o2 = TimezoneOffset.new(-18000, 3600, :EDT)
442
572
 
443
- t1 = TimezoneTransitionInfo.new(o2, o1, 1081062000)
444
- t2 = TimezoneTransitionInfo.new(o1, o2, 1099202400)
445
- t3 = TimezoneTransitionInfo.new(o2, o1, 1112511600)
573
+ t1 = TestTimezoneTransition.new(o2, o1, 1081062000)
574
+ t2 = TestTimezoneTransition.new(o1, o2, 1099202400)
575
+ t3 = TestTimezoneTransition.new(o2, o1, 1112511600)
446
576
 
447
577
  p1 = TimezonePeriod.new(t1, t2)
448
578
  p2 = TimezonePeriod.new(t2, t3)
@@ -460,12 +590,12 @@ class TCTimezone < Test::Unit::TestCase
460
590
  def test_period_for_local_default_dst_set_false
461
591
  Timezone.default_dst = false
462
592
 
463
- o1 = TimezoneOffsetInfo.new(-18000, 0, :EST)
464
- o2 = TimezoneOffsetInfo.new(-18000, 3600, :EDT)
593
+ o1 = TimezoneOffset.new(-18000, 0, :EST)
594
+ o2 = TimezoneOffset.new(-18000, 3600, :EDT)
465
595
 
466
- t1 = TimezoneTransitionInfo.new(o2, o1, 1081062000)
467
- t2 = TimezoneTransitionInfo.new(o1, o2, 1099202400)
468
- t3 = TimezoneTransitionInfo.new(o2, o1, 1112511600)
596
+ t1 = TestTimezoneTransition.new(o2, o1, 1081062000)
597
+ t2 = TestTimezoneTransition.new(o1, o2, 1099202400)
598
+ t3 = TestTimezoneTransition.new(o2, o1, 1112511600)
469
599
 
470
600
  p1 = TimezonePeriod.new(t1, t2)
471
601
  p2 = TimezonePeriod.new(t2, t3)
@@ -481,12 +611,12 @@ class TCTimezone < Test::Unit::TestCase
481
611
  end
482
612
 
483
613
  def test_period_for_local_dst_flag_resolved
484
- o1 = TimezoneOffsetInfo.new(-18000, 0, :EST)
485
- o2 = TimezoneOffsetInfo.new(-18000, 3600, :EDT)
614
+ o1 = TimezoneOffset.new(-18000, 0, :EST)
615
+ o2 = TimezoneOffset.new(-18000, 3600, :EDT)
486
616
 
487
- t1 = TimezoneTransitionInfo.new(o2, o1, 1081062000)
488
- t2 = TimezoneTransitionInfo.new(o1, o2, 1099202400)
489
- t3 = TimezoneTransitionInfo.new(o2, o1, 1112511600)
617
+ t1 = TestTimezoneTransition.new(o2, o1, 1081062000)
618
+ t2 = TestTimezoneTransition.new(o1, o2, 1099202400)
619
+ t3 = TestTimezoneTransition.new(o2, o1, 1112511600)
490
620
 
491
621
  p1 = TimezonePeriod.new(t1, t2)
492
622
  p2 = TimezonePeriod.new(t2, t3)
@@ -502,12 +632,12 @@ class TCTimezone < Test::Unit::TestCase
502
632
  end
503
633
 
504
634
  def test_period_for_local_dst_block_called
505
- o1 = TimezoneOffsetInfo.new(-18000, 0, :EST)
506
- o2 = TimezoneOffsetInfo.new(-18000, 3600, :EDT)
635
+ o1 = TimezoneOffset.new(-18000, 0, :EST)
636
+ o2 = TimezoneOffset.new(-18000, 3600, :EDT)
507
637
 
508
- t1 = TimezoneTransitionInfo.new(o2, o1, 1081062000)
509
- t2 = TimezoneTransitionInfo.new(o1, o2, 1099202400)
510
- t3 = TimezoneTransitionInfo.new(o2, o1, 1112511600)
638
+ t1 = TestTimezoneTransition.new(o2, o1, 1081062000)
639
+ t2 = TestTimezoneTransition.new(o1, o2, 1099202400)
640
+ t3 = TestTimezoneTransition.new(o2, o1, 1112511600)
511
641
 
512
642
  p1 = TimezonePeriod.new(t1, t2)
513
643
  p2 = TimezonePeriod.new(t2, t3)
@@ -536,14 +666,14 @@ class TCTimezone < Test::Unit::TestCase
536
666
  # 24 minutes and both periods were non-DST. Hence the block should be
537
667
  # called regardless of the value of the Boolean dst parameter.
538
668
 
539
- o0 = TimezoneOffsetInfo.new(5040, 0, :LMT)
540
- o1 = TimezoneOffsetInfo.new(5040, 0, :WMT)
541
- o2 = TimezoneOffsetInfo.new(3600, 0, :CET)
542
- o3 = TimezoneOffsetInfo.new(3600, 3600, :CEST)
669
+ o0 = TimezoneOffset.new(5040, 0, :LMT)
670
+ o1 = TimezoneOffset.new(5040, 0, :WMT)
671
+ o2 = TimezoneOffset.new(3600, 0, :CET)
672
+ o3 = TimezoneOffset.new(3600, 3600, :CEST)
543
673
 
544
- t1 = TimezoneTransitionInfo.new(o1, o0, 288925853, 120)
545
- t2 = TimezoneTransitionInfo.new(o2, o1, 290485733, 120)
546
- t3 = TimezoneTransitionInfo.new(o3, o2, 29051813, 12)
674
+ t1 = TestTimezoneTransition.new(o1, o0, DateTime.new(1879, 12, 31, 22, 36, 0))
675
+ t2 = TestTimezoneTransition.new(o2, o1, DateTime.new(1915, 8, 4, 22, 36, 0))
676
+ t3 = TestTimezoneTransition.new(o3, o2, DateTime.new(1916, 4, 30, 22, 0, 0))
547
677
 
548
678
  p1 = TimezonePeriod.new(t1, t2)
549
679
  p2 = TimezonePeriod.new(t2, t3)
@@ -568,12 +698,12 @@ class TCTimezone < Test::Unit::TestCase
568
698
  end
569
699
 
570
700
  def test_period_for_local_block_ambiguous
571
- o1 = TimezoneOffsetInfo.new(-18000, 0, :EST)
572
- o2 = TimezoneOffsetInfo.new(-18000, 3600, :EDT)
701
+ o1 = TimezoneOffset.new(-18000, 0, :EST)
702
+ o2 = TimezoneOffset.new(-18000, 3600, :EDT)
573
703
 
574
- t1 = TimezoneTransitionInfo.new(o2, o1, 1081062000)
575
- t2 = TimezoneTransitionInfo.new(o1, o2, 1099202400)
576
- t3 = TimezoneTransitionInfo.new(o2, o1, 1112511600)
704
+ t1 = TestTimezoneTransition.new(o2, o1, 1081062000)
705
+ t2 = TestTimezoneTransition.new(o1, o2, 1099202400)
706
+ t3 = TestTimezoneTransition.new(o2, o1, 1112511600)
577
707
 
578
708
  p1 = TimezonePeriod.new(t1, t2)
579
709
  p2 = TimezonePeriod.new(t2, t3)
@@ -610,12 +740,12 @@ class TCTimezone < Test::Unit::TestCase
610
740
  tu2 = Time.local(2005,6,18,16,24,23,567000)
611
741
  ts = t.to_i
612
742
 
613
- o1 = TimezoneOffsetInfo.new(0, 0, :GMT)
614
- o2 = TimezoneOffsetInfo.new(0, 3600, :BST)
743
+ o1 = TimezoneOffset.new(0, 0, :GMT)
744
+ o2 = TimezoneOffset.new(0, 3600, :BST)
615
745
 
616
746
  period = TimezonePeriod.new(
617
- TimezoneTransitionInfo.new(o2, o1, 1111885200),
618
- TimezoneTransitionInfo.new(o1, o2, 1130634000))
747
+ TestTimezoneTransition.new(o2, o1, 1111885200),
748
+ TestTimezoneTransition.new(o1, o2, 1130634000))
619
749
 
620
750
  assert_equal(DateTime.new(2005,6,18,17,24,23), TestTimezone.new('Europe/London', period, [], dt).utc_to_local(dt))
621
751
  assert_equal(DateTime.new(2005,6,18,17,24,23), TestTimezone.new('Europe/London', period, [], dt2).utc_to_local(dt2))
@@ -638,25 +768,25 @@ class TCTimezone < Test::Unit::TestCase
638
768
  tu = Time.utc(2005,6,18,16,24,23,567000)
639
769
  tu2 = Time.local(2005,6,18,16,24,23,567000)
640
770
 
641
- o1 = TimezoneOffsetInfo.new(0, 0, :GMT)
642
- o2 = TimezoneOffsetInfo.new(0, 3600, :BST)
771
+ o1 = TimezoneOffset.new(0, 0, :GMT)
772
+ o2 = TimezoneOffset.new(0, 3600, :BST)
643
773
 
644
774
  period = TimezonePeriod.new(
645
- TimezoneTransitionInfo.new(o2, o1, 1111885200),
646
- TimezoneTransitionInfo.new(o1, o2, 1130634000))
775
+ TestTimezoneTransition.new(o2, o1, 1111885200),
776
+ TestTimezoneTransition.new(o1, o2, 1130634000))
647
777
 
648
778
  assert_equal(0, TestTimezone.new('Europe/London', period, [], dt).utc_to_local(dt).offset)
649
779
  assert_equal(0, TestTimezone.new('Europe/London', period, [], dt2).utc_to_local(dt2).offset)
650
780
  assert_equal(0, TestTimezone.new('Europe/London', period, [], dtu).utc_to_local(dtu).offset)
651
781
  assert_equal(0, TestTimezone.new('Europe/London', period, [], dtu2).utc_to_local(dtu2).offset)
652
782
  assert_equal(0, TestTimezone.new('Europe/London', period, [], t).utc_to_local(t).utc_offset)
653
- assert_equal('UTC', TestTimezone.new('Europe/London', period, [], t).utc_to_local(t).zone)
783
+ assert(TestTimezone.new('Europe/London', period, [], t).utc_to_local(t).utc?)
654
784
  assert_equal(0, TestTimezone.new('Europe/London', period, [], t2).utc_to_local(t2).utc_offset)
655
- assert_equal('UTC', TestTimezone.new('Europe/London', period, [], t2).utc_to_local(t2).zone)
785
+ assert(TestTimezone.new('Europe/London', period, [], t2).utc_to_local(t2).utc?)
656
786
  assert_equal(0, TestTimezone.new('Europe/London', period, [], tu).utc_to_local(tu).utc_offset)
657
- assert_equal('UTC', TestTimezone.new('Europe/London', period, [], tu).utc_to_local(tu).zone)
787
+ assert(TestTimezone.new('Europe/London', period, [], tu).utc_to_local(tu).utc?)
658
788
  assert_equal(0, TestTimezone.new('Europe/London', period, [], tu2).utc_to_local(tu2).utc_offset)
659
- assert_equal('UTC', TestTimezone.new('Europe/London', period, [], tu2).utc_to_local(tu2).zone)
789
+ assert(TestTimezone.new('Europe/London', period, [], tu2).utc_to_local(tu2).utc?)
660
790
  end
661
791
 
662
792
  def test_local_to_utc
@@ -670,12 +800,12 @@ class TCTimezone < Test::Unit::TestCase
670
800
  tu2 = Time.local(2005,6,18,16,24,23,567000)
671
801
  ts = t.to_i
672
802
 
673
- o1 = TimezoneOffsetInfo.new(0, 0, :GMT)
674
- o2 = TimezoneOffsetInfo.new(0, 3600, :BST)
803
+ o1 = TimezoneOffset.new(0, 0, :GMT)
804
+ o2 = TimezoneOffset.new(0, 3600, :BST)
675
805
 
676
806
  period = TimezonePeriod.new(
677
- TimezoneTransitionInfo.new(o2, o1, 1111885200),
678
- TimezoneTransitionInfo.new(o1, o2, 1130634000))
807
+ TestTimezoneTransition.new(o2, o1, 1111885200),
808
+ TestTimezoneTransition.new(o1, o2, 1130634000))
679
809
 
680
810
  assert_equal(DateTime.new(2005,6,18,15,24,23), TestTimezone.new('Europe/London', nil, [period], dt).local_to_utc(dt))
681
811
  assert_equal(DateTime.new(2005,6,18,15,24,23), TestTimezone.new('Europe/London', nil, [period], dt2).local_to_utc(dt2))
@@ -698,25 +828,25 @@ class TCTimezone < Test::Unit::TestCase
698
828
  tu = Time.utc(2005,6,18,16,24,23,567000)
699
829
  tu2 = Time.local(2005,6,18,16,24,23,567000)
700
830
 
701
- o1 = TimezoneOffsetInfo.new(0, 0, :GMT)
702
- o2 = TimezoneOffsetInfo.new(0, 3600, :BST)
831
+ o1 = TimezoneOffset.new(0, 0, :GMT)
832
+ o2 = TimezoneOffset.new(0, 3600, :BST)
703
833
 
704
834
  period = TimezonePeriod.new(
705
- TimezoneTransitionInfo.new(o2, o1, 1111885200),
706
- TimezoneTransitionInfo.new(o1, o2, 1130634000))
835
+ TestTimezoneTransition.new(o2, o1, 1111885200),
836
+ TestTimezoneTransition.new(o1, o2, 1130634000))
707
837
 
708
838
  assert_equal(0, TestTimezone.new('Europe/London', nil, [period], dt).local_to_utc(dt).offset)
709
839
  assert_equal(0, TestTimezone.new('Europe/London', nil, [period], dt2).local_to_utc(dt2).offset)
710
840
  assert_equal(0, TestTimezone.new('Europe/London', nil, [period], dtu).local_to_utc(dtu).offset)
711
841
  assert_equal(0, TestTimezone.new('Europe/London', nil, [period], dtu2).local_to_utc(dtu2).offset)
712
842
  assert_equal(0, TestTimezone.new('Europe/London', nil, [period], t).local_to_utc(t).utc_offset)
713
- assert_equal('UTC', TestTimezone.new('Europe/London', nil, [period], t).local_to_utc(t).zone)
843
+ assert(TestTimezone.new('Europe/London', nil, [period], t).local_to_utc(t).utc?)
714
844
  assert_equal(0, TestTimezone.new('Europe/London', nil, [period], t2).local_to_utc(t2).utc_offset)
715
- assert_equal('UTC', TestTimezone.new('Europe/London', nil, [period], t2).local_to_utc(t2).zone)
845
+ assert(TestTimezone.new('Europe/London', nil, [period], t2).local_to_utc(t2).utc?)
716
846
  assert_equal(0, TestTimezone.new('Europe/London', nil, [period], tu).local_to_utc(tu).utc_offset)
717
- assert_equal('UTC', TestTimezone.new('Europe/London', nil, [period], tu).local_to_utc(tu).zone)
847
+ assert(TestTimezone.new('Europe/London', nil, [period], tu).local_to_utc(tu).utc?)
718
848
  assert_equal(0, TestTimezone.new('Europe/London', nil, [period], tu2).local_to_utc(tu2).utc_offset)
719
- assert_equal('UTC', TestTimezone.new('Europe/London', nil, [period], tu2).local_to_utc(tu2).zone)
849
+ assert(TestTimezone.new('Europe/London', nil, [period], tu2).local_to_utc(tu2).utc?)
720
850
  end
721
851
 
722
852
  def test_local_to_utc_invalid
@@ -734,12 +864,12 @@ class TCTimezone < Test::Unit::TestCase
734
864
  end
735
865
 
736
866
  def test_local_to_utc_ambiguous
737
- o1 = TimezoneOffsetInfo.new(-18000, 0, :EST)
738
- o2 = TimezoneOffsetInfo.new(-18000, 3600, :EDT)
867
+ o1 = TimezoneOffset.new(-18000, 0, :EST)
868
+ o2 = TimezoneOffset.new(-18000, 3600, :EDT)
739
869
 
740
- t1 = TimezoneTransitionInfo.new(o2, o1, 1081062000)
741
- t2 = TimezoneTransitionInfo.new(o1, o2, 1099202400)
742
- t3 = TimezoneTransitionInfo.new(o2, o1, 1112511600)
870
+ t1 = TestTimezoneTransition.new(o2, o1, 1081062000)
871
+ t2 = TestTimezoneTransition.new(o1, o2, 1099202400)
872
+ t3 = TestTimezoneTransition.new(o2, o1, 1112511600)
743
873
 
744
874
  p1 = TimezonePeriod.new(t1, t2)
745
875
  p2 = TimezonePeriod.new(t2, t3)
@@ -762,12 +892,12 @@ class TCTimezone < Test::Unit::TestCase
762
892
  end
763
893
 
764
894
  def test_local_to_utc_not_found
765
- o1 = TimezoneOffsetInfo.new(-18000, 0, :EST)
766
- o2 = TimezoneOffsetInfo.new(-18000, 3600, :EDT)
895
+ o1 = TimezoneOffset.new(-18000, 0, :EST)
896
+ o2 = TimezoneOffset.new(-18000, 3600, :EDT)
767
897
 
768
- t1 = TimezoneTransitionInfo.new(o1, o2, 1067148000)
769
- t2 = TimezoneTransitionInfo.new(o2, o1, 1081062000)
770
- t3 = TimezoneTransitionInfo.new(o1, o2, 1099202400)
898
+ t1 = TestTimezoneTransition.new(o1, o2, 1067148000)
899
+ t2 = TestTimezoneTransition.new(o2, o1, 1081062000)
900
+ t3 = TestTimezoneTransition.new(o1, o2, 1099202400)
771
901
 
772
902
  p1 = TimezonePeriod.new(t1, t2)
773
903
  p2 = TimezonePeriod.new(t2, t3)
@@ -788,12 +918,12 @@ class TCTimezone < Test::Unit::TestCase
788
918
  def test_local_to_utc_default_dst_set_true
789
919
  Timezone.default_dst = true
790
920
 
791
- o1 = TimezoneOffsetInfo.new(-18000, 0, :EST)
792
- o2 = TimezoneOffsetInfo.new(-18000, 3600, :EDT)
921
+ o1 = TimezoneOffset.new(-18000, 0, :EST)
922
+ o2 = TimezoneOffset.new(-18000, 3600, :EDT)
793
923
 
794
- t1 = TimezoneTransitionInfo.new(o2, o1, 1081062000)
795
- t2 = TimezoneTransitionInfo.new(o1, o2, 1099202400)
796
- t3 = TimezoneTransitionInfo.new(o2, o1, 1112511600)
924
+ t1 = TestTimezoneTransition.new(o2, o1, 1081062000)
925
+ t2 = TestTimezoneTransition.new(o1, o2, 1099202400)
926
+ t3 = TestTimezoneTransition.new(o2, o1, 1112511600)
797
927
 
798
928
  p1 = TimezonePeriod.new(t1, t2)
799
929
  p2 = TimezonePeriod.new(t2, t3)
@@ -811,12 +941,12 @@ class TCTimezone < Test::Unit::TestCase
811
941
  def test_local_to_utc_default_dst_set_false
812
942
  Timezone.default_dst = false
813
943
 
814
- o1 = TimezoneOffsetInfo.new(-18000, 0, :EST)
815
- o2 = TimezoneOffsetInfo.new(-18000, 3600, :EDT)
944
+ o1 = TimezoneOffset.new(-18000, 0, :EST)
945
+ o2 = TimezoneOffset.new(-18000, 3600, :EDT)
816
946
 
817
- t1 = TimezoneTransitionInfo.new(o2, o1, 1081062000)
818
- t2 = TimezoneTransitionInfo.new(o1, o2, 1099202400)
819
- t3 = TimezoneTransitionInfo.new(o2, o1, 1112511600)
947
+ t1 = TestTimezoneTransition.new(o2, o1, 1081062000)
948
+ t2 = TestTimezoneTransition.new(o1, o2, 1099202400)
949
+ t3 = TestTimezoneTransition.new(o2, o1, 1112511600)
820
950
 
821
951
  p1 = TimezonePeriod.new(t1, t2)
822
952
  p2 = TimezonePeriod.new(t2, t3)
@@ -832,12 +962,12 @@ class TCTimezone < Test::Unit::TestCase
832
962
  end
833
963
 
834
964
  def test_local_to_utc_dst_flag_resolved
835
- o1 = TimezoneOffsetInfo.new(-18000, 0, :EST)
836
- o2 = TimezoneOffsetInfo.new(-18000, 3600, :EDT)
965
+ o1 = TimezoneOffset.new(-18000, 0, :EST)
966
+ o2 = TimezoneOffset.new(-18000, 3600, :EDT)
837
967
 
838
- t1 = TimezoneTransitionInfo.new(o2, o1, 1081062000)
839
- t2 = TimezoneTransitionInfo.new(o1, o2, 1099202400)
840
- t3 = TimezoneTransitionInfo.new(o2, o1, 1112511600)
968
+ t1 = TestTimezoneTransition.new(o2, o1, 1081062000)
969
+ t2 = TestTimezoneTransition.new(o1, o2, 1099202400)
970
+ t3 = TestTimezoneTransition.new(o2, o1, 1112511600)
841
971
 
842
972
  p1 = TimezonePeriod.new(t1, t2)
843
973
  p2 = TimezonePeriod.new(t2, t3)
@@ -852,12 +982,12 @@ class TCTimezone < Test::Unit::TestCase
852
982
  end
853
983
 
854
984
  def test_local_to_utc_dst_block_called
855
- o1 = TimezoneOffsetInfo.new(-18000, 0, :EST)
856
- o2 = TimezoneOffsetInfo.new(-18000, 3600, :EDT)
985
+ o1 = TimezoneOffset.new(-18000, 0, :EST)
986
+ o2 = TimezoneOffset.new(-18000, 3600, :EDT)
857
987
 
858
- t1 = TimezoneTransitionInfo.new(o2, o1, 1081062000)
859
- t2 = TimezoneTransitionInfo.new(o1, o2, 1099202400)
860
- t3 = TimezoneTransitionInfo.new(o2, o1, 1112511600)
988
+ t1 = TestTimezoneTransition.new(o2, o1, 1081062000)
989
+ t2 = TestTimezoneTransition.new(o1, o2, 1099202400)
990
+ t3 = TestTimezoneTransition.new(o2, o1, 1112511600)
861
991
 
862
992
  p1 = TimezonePeriod.new(t1, t2)
863
993
  p2 = TimezonePeriod.new(t2, t3)
@@ -885,14 +1015,14 @@ class TCTimezone < Test::Unit::TestCase
885
1015
  # 24 minutes and both periods were non-DST. Hence the block should be
886
1016
  # called regardless of the value of the Boolean dst parameter.
887
1017
 
888
- o0 = TimezoneOffsetInfo.new(5040, 0, :LMT)
889
- o1 = TimezoneOffsetInfo.new(5040, 0, :WMT)
890
- o2 = TimezoneOffsetInfo.new(3600, 0, :CET)
891
- o3 = TimezoneOffsetInfo.new(3600, 3600, :CEST)
1018
+ o0 = TimezoneOffset.new(5040, 0, :LMT)
1019
+ o1 = TimezoneOffset.new(5040, 0, :WMT)
1020
+ o2 = TimezoneOffset.new(3600, 0, :CET)
1021
+ o3 = TimezoneOffset.new(3600, 3600, :CEST)
892
1022
 
893
- t1 = TimezoneTransitionInfo.new(o1, o0, 288925853, 120)
894
- t2 = TimezoneTransitionInfo.new(o2, o1, 290485733, 120)
895
- t3 = TimezoneTransitionInfo.new(o3, o2, 29051813, 12)
1023
+ t1 = TestTimezoneTransition.new(o1, o0, DateTime.new(1879, 12, 31, 22, 36, 0))
1024
+ t2 = TestTimezoneTransition.new(o2, o1, DateTime.new(1915, 8, 4, 22, 36, 0))
1025
+ t3 = TestTimezoneTransition.new(o3, o2, DateTime.new(1916, 4, 30, 22, 0, 0))
896
1026
 
897
1027
  p1 = TimezonePeriod.new(t1, t2)
898
1028
  p2 = TimezonePeriod.new(t2, t3)
@@ -922,12 +1052,12 @@ class TCTimezone < Test::Unit::TestCase
922
1052
  end
923
1053
 
924
1054
  def test_local_to_utc_block_ambiguous
925
- o1 = TimezoneOffsetInfo.new(-18000, 0, :EST)
926
- o2 = TimezoneOffsetInfo.new(-18000, 3600, :EDT)
1055
+ o1 = TimezoneOffset.new(-18000, 0, :EST)
1056
+ o2 = TimezoneOffset.new(-18000, 3600, :EDT)
927
1057
 
928
- t1 = TimezoneTransitionInfo.new(o2, o1, 1081062000)
929
- t2 = TimezoneTransitionInfo.new(o1, o2, 1099202400)
930
- t3 = TimezoneTransitionInfo.new(o2, o1, 1112511600)
1058
+ t1 = TestTimezoneTransition.new(o2, o1, 1081062000)
1059
+ t2 = TestTimezoneTransition.new(o1, o2, 1099202400)
1060
+ t3 = TestTimezoneTransition.new(o2, o1, 1112511600)
931
1061
 
932
1062
  p1 = TimezonePeriod.new(t1, t2)
933
1063
  p2 = TimezonePeriod.new(t2, t3)
@@ -944,6 +1074,123 @@ class TCTimezone < Test::Unit::TestCase
944
1074
  assert_raises(AmbiguousTime) { tz.local_to_utc(dt) {|periods| raise AmbiguousTime, 'Ambiguous time'} }
945
1075
  end
946
1076
 
1077
+ def test_offsets_up_to
1078
+ o1 = TimezoneOffset.new(-17900, 0, :TESTLMT)
1079
+ o2 = TimezoneOffset.new(-18000, 3600, :TESTD)
1080
+ o3 = TimezoneOffset.new(-18000, 0, :TESTS)
1081
+ o4 = TimezoneOffset.new(-21600, 3600, :TESTD)
1082
+ o5 = TimezoneOffset.new(-21600, 0, :TESTS)
1083
+
1084
+ t1 = TestTimezoneTransition.new(o2, o1, Time.utc(2010, 4,1,1,0,0).to_i)
1085
+ t2 = TestTimezoneTransition.new(o3, o2, Time.utc(2010,10,1,1,0,0).to_i)
1086
+ t3 = TestTimezoneTransition.new(o2, o3, Time.utc(2011, 3,1,1,0,0).to_i)
1087
+ t4 = TestTimezoneTransition.new(o4, o2, Time.utc(2011, 4,1,1,0,0).to_i)
1088
+ t5 = TestTimezoneTransition.new(o3, o4, Time.utc(2011,10,1,1,0,0).to_i)
1089
+ t6 = TestTimezoneTransition.new(o5, o3, Time.utc(2012, 3,1,1,0,0).to_i)
1090
+
1091
+ assert_array_same_items([o1, o2, o3, o4, o5],
1092
+ OffsetsUpToTestTimezone.new('Test/Zone', Time.utc(2012,3,1,1,0,1), nil, [t1, t2, t3, t4, t5, t6]).
1093
+ offsets_up_to(Time.utc(2012,3,1,1,0,1)))
1094
+ assert_array_same_items([o2, o3, o4, o5],
1095
+ OffsetsUpToTestTimezone.new('Test/Zone', Time.utc(2012,3,1,1,0,1), Time.utc(2010,4,1,1,0,0), [t1, t2, t3, t4, t5, t6]).
1096
+ offsets_up_to(Time.utc(2012,3,1,1,0,1), Time.utc(2010,4,1,1,0,0)))
1097
+ assert_array_same_items([o1, o2, o3, o4],
1098
+ OffsetsUpToTestTimezone.new('Test/Zone', Time.utc(2012,3,1,1,0,0), nil, [t1, t2, t3, t4, t5]).
1099
+ offsets_up_to(Time.utc(2012,3,1,1,0,0)))
1100
+ assert_array_same_items([o2, o3, o4, o5],
1101
+ OffsetsUpToTestTimezone.new('Test/Zone', Time.utc(2012,3,1,1,0,1), Time.utc(2010,4,1,1,0,1), [t2, t3, t4, t5, t6]).
1102
+ offsets_up_to(Time.utc(2012,3,1,1,0,1), Time.utc(2010,4,1,1,0,1)))
1103
+ assert_array_same_items([o2, o3],
1104
+ OffsetsUpToTestTimezone.new('Test/Zone', Time.utc(2011,3,1,2,0,0), Time.utc(2011,3,1,0,0,0), [t3]).
1105
+ offsets_up_to(Time.utc(2011,3,1,2,0,0), Time.utc(2011,3,1,0,0,0)))
1106
+ assert_array_same_items([o3, o4],
1107
+ OffsetsUpToTestTimezone.new('Test/Zone', Time.utc(2012,3,1,1,0,0), Time.utc(2011,4,1,1,0,0), [t4, t5]).
1108
+ offsets_up_to(Time.utc(2012,3,1,1,0,0), Time.utc(2011,4,1,1,0,0)))
1109
+
1110
+ assert_array_same_items([o1, o2, o3, o4, o5],
1111
+ OffsetsUpToTestTimezone.new('Test/Zone', Time.utc(2012,3,1,1,0,1).to_i, nil, [t1, t2, t3, t4, t5, t6]).
1112
+ offsets_up_to(Time.utc(2012,3,1,1,0,1).to_i))
1113
+ assert_array_same_items([o2, o3, o4, o5],
1114
+ OffsetsUpToTestTimezone.new('Test/Zone', Time.utc(2012,3,1,1,0,1).to_i, Time.utc(2010,4,1,1,0,0).to_i, [t1, t2, t3, t4, t5, t6]).
1115
+ offsets_up_to(Time.utc(2012,3,1,1,0,1).to_i, Time.utc(2010,4,1,1,0,0).to_i))
1116
+ assert_array_same_items([o1, o2, o3, o4],
1117
+ OffsetsUpToTestTimezone.new('Test/Zone', Time.utc(2012,3,1,1,0,0).to_i, nil, [t1, t2, t3, t4, t5]).
1118
+ offsets_up_to(Time.utc(2012,3,1,1,0,0).to_i))
1119
+ assert_array_same_items([o2, o3, o4, o5],
1120
+ OffsetsUpToTestTimezone.new('Test/Zone', Time.utc(2012,3,1,1,0,1).to_i, Time.utc(2010,4,1,1,0,1).to_i, [t2, t3, t4, t5, t6]).
1121
+ offsets_up_to(Time.utc(2012,3,1,1,0,1).to_i, Time.utc(2010,4,1,1,0,1).to_i))
1122
+ assert_array_same_items([o2, o3],
1123
+ OffsetsUpToTestTimezone.new('Test/Zone', Time.utc(2011,3,1,2,0,0).to_i, Time.utc(2011,3,1,0,0,0).to_i, [t3]).
1124
+ offsets_up_to(Time.utc(2011,3,1,2,0,0).to_i, Time.utc(2011,3,1,0,0,0).to_i))
1125
+ assert_array_same_items([o3, o4],
1126
+ OffsetsUpToTestTimezone.new('Test/Zone', Time.utc(2012,3,1,1,0,0).to_i, Time.utc(2011,4,1,1,0,0).to_i, [t4, t5]).
1127
+ offsets_up_to(Time.utc(2012,3,1,1,0,0).to_i, Time.utc(2011,4,1,1,0,0).to_i))
1128
+
1129
+ assert_array_same_items([o1, o2, o3, o4, o5],
1130
+ OffsetsUpToTestTimezone.new('Test/Zone', DateTime.new(2012,3,1,1,0,1), nil, [t1, t2, t3, t4, t5, t6]).
1131
+ offsets_up_to(DateTime.new(2012,3,1,1,0,1)))
1132
+ assert_array_same_items([o2, o3, o4, o5],
1133
+ OffsetsUpToTestTimezone.new('Test/Zone', DateTime.new(2012,3,1,1,0,1), DateTime.new(2010,4,1,1,0,0), [t1, t2, t3, t4, t5, t6]).
1134
+ offsets_up_to(DateTime.new(2012,3,1,1,0,1), DateTime.new(2010,4,1,1,0,0)))
1135
+ assert_array_same_items([o1, o2, o3, o4],
1136
+ OffsetsUpToTestTimezone.new('Test/Zone', DateTime.new(2012,3,1,1,0,0), nil, [t1, t2, t3, t4, t5]).
1137
+ offsets_up_to(DateTime.new(2012,3,1,1,0,0)))
1138
+ assert_array_same_items([o2, o3, o4, o5],
1139
+ OffsetsUpToTestTimezone.new('Test/Zone', DateTime.new(2012,3,1,1,0,1), DateTime.new(2010,4,1,1,0,1), [t2, t3, t4, t5, t6]).
1140
+ offsets_up_to(DateTime.new(2012,3,1,1,0,1), DateTime.new(2010,4,1,1,0,1)))
1141
+ assert_array_same_items([o2, o3],
1142
+ OffsetsUpToTestTimezone.new('Test/Zone', DateTime.new(2011,3,1,2,0,0), DateTime.new(2011,3,1,0,0,0), [t3]).
1143
+ offsets_up_to(DateTime.new(2011,3,1,2,0,0), DateTime.new(2011,3,1,0,0,0)))
1144
+ assert_array_same_items([o3, o4],
1145
+ OffsetsUpToTestTimezone.new('Test/Zone', DateTime.new(2012,3,1,1,0,0), DateTime.new(2011,4,1,1,0,0), [t4, t5]).
1146
+ offsets_up_to(DateTime.new(2012,3,1,1,0,0), DateTime.new(2011,4,1,1,0,0)))
1147
+ end
1148
+
1149
+ def test_offsets_up_to_no_transitions
1150
+ o = TimezoneOffset.new(600, 0, :LMT)
1151
+ p = TimezonePeriod.new(nil, nil, o)
1152
+
1153
+ assert_array_same_items([o],
1154
+ OffsetsUpToNoTransitionsTestTimezone.new('Test/Zone', Time.utc(2000,1,1,1,0,0), nil, p).
1155
+ offsets_up_to(Time.utc(2000,1,1,1,0,0)))
1156
+ assert_array_same_items([o],
1157
+ OffsetsUpToNoTransitionsTestTimezone.new('Test/Zone', Time.utc(2000,1,1,1,0,0), Time.utc(1990,1,1,1,0,0), p).
1158
+ offsets_up_to(Time.utc(2000,1,1,1,0,0), Time.utc(1990,1,1,1,0,0)))
1159
+
1160
+ assert_array_same_items([o],
1161
+ OffsetsUpToNoTransitionsTestTimezone.new('Test/Zone', Time.utc(2000,1,1,1,0,0).to_i, nil, p).
1162
+ offsets_up_to(Time.utc(2000,1,1,1,0,0).to_i))
1163
+ assert_array_same_items([o],
1164
+ OffsetsUpToNoTransitionsTestTimezone.new('Test/Zone', Time.utc(2000,1,1,1,0,0).to_i, Time.utc(1990,1,1,1,0,0).to_i, p).
1165
+ offsets_up_to(Time.utc(2000,1,1,1,0,0).to_i, Time.utc(1990,1,1,1,0,0).to_i))
1166
+
1167
+ assert_array_same_items([o],
1168
+ OffsetsUpToNoTransitionsTestTimezone.new('Test/Zone', DateTime.new(2000,1,1,1,0,0), nil, p).
1169
+ offsets_up_to(DateTime.new(2000,1,1,1,0,0)))
1170
+ assert_array_same_items([o],
1171
+ OffsetsUpToNoTransitionsTestTimezone.new('Test/Zone', DateTime.new(2000,1,1,1,0,0), DateTime.new(1990,1,1,1,0,0), p).
1172
+ offsets_up_to(DateTime.new(2000,1,1,1,0,0), DateTime.new(1990,1,1,1,0,0)))
1173
+ end
1174
+
1175
+ def test_offsets_up_to_utc_to_not_greater_than_utc_from
1176
+ o = TimezoneOffset.new(600, 0, :LMT)
1177
+
1178
+ assert_raises(ArgumentError) do
1179
+ OffsetsUpToTestTimezone.new('Test/Zone', Time.utc(2012,8,1,0,0,0), Time.utc(2012,8,1,0,0,0), []).
1180
+ offsets_up_to(Time.utc(2012,8,1,0,0,0), Time.utc(2012,8,1,0,0,0))
1181
+ end
1182
+
1183
+ assert_raises(ArgumentError) do
1184
+ OffsetsUpToTestTimezone.new('Test/Zone', Time.utc(2012,8,1,0,0,0).to_i, Time.utc(2012,8,1,0,0,0).to_i, []).
1185
+ offsets_up_to(Time.utc(2012,8,1,0,0,0).to_i, Time.utc(2012,8,1,0,0,0).to_i)
1186
+ end
1187
+
1188
+ assert_raises(ArgumentError) do
1189
+ OffsetsUpToTestTimezone.new('Test/Zone', DateTime.new(2012,8,1,0,0,0), DateTime.new(2012,8,1,0,0,0), []).
1190
+ offsets_up_to(DateTime.new(2012,8,1,0,0,0), DateTime.new(2012,8,1,0,0,0))
1191
+ end
1192
+ end
1193
+
947
1194
  def test_now
948
1195
  assert_kind_of(Time, Timezone.get('Europe/London').now)
949
1196
  end