tzinfo 1.2.4 → 1.2.7

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 (40) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CHANGES.md +75 -48
  5. data/LICENSE +1 -1
  6. data/README.md +9 -8
  7. data/lib/tzinfo/country_timezone.rb +14 -2
  8. data/lib/tzinfo/data_source.rb +1 -1
  9. data/lib/tzinfo/ruby_core_support.rb +24 -1
  10. data/lib/tzinfo/ruby_country_info.rb +6 -2
  11. data/lib/tzinfo/ruby_data_source.rb +24 -20
  12. data/lib/tzinfo/time_or_datetime.rb +12 -5
  13. data/lib/tzinfo/timezone.rb +10 -6
  14. data/lib/tzinfo/timezone_offset.rb +26 -3
  15. data/lib/tzinfo/timezone_period.rb +29 -5
  16. data/lib/tzinfo/timezone_proxy.rb +7 -1
  17. data/lib/tzinfo/timezone_transition.rb +12 -2
  18. data/lib/tzinfo/timezone_transition_definition.rb +6 -3
  19. data/lib/tzinfo/zoneinfo_country_info.rb +3 -1
  20. data/lib/tzinfo/zoneinfo_data_source.rb +8 -0
  21. data/lib/tzinfo/zoneinfo_timezone_info.rb +13 -7
  22. data/test/tc_country.rb +6 -4
  23. data/test/tc_country_timezone.rb +12 -0
  24. data/test/tc_ruby_country_info.rb +30 -0
  25. data/test/tc_ruby_data_source.rb +26 -2
  26. data/test/tc_time_or_datetime.rb +27 -6
  27. data/test/tc_timezone.rb +13 -2
  28. data/test/tc_timezone_period.rb +7 -0
  29. data/test/tc_timezone_proxy.rb +9 -0
  30. data/test/tc_timezone_transition.rb +14 -0
  31. data/test/tc_timezone_transition_definition.rb +11 -0
  32. data/test/tc_transition_data_timezone_info.rb +11 -1
  33. data/test/tc_zoneinfo_country_info.rb +14 -0
  34. data/test/tc_zoneinfo_data_source.rb +11 -2
  35. data/test/tc_zoneinfo_timezone_info.rb +108 -0
  36. data/test/test_utils.rb +63 -5
  37. data/test/ts_all_zoneinfo.rb +3 -1
  38. data/tzinfo.gemspec +2 -2
  39. metadata +22 -24
  40. metadata.gz.sig +0 -0
@@ -2,6 +2,10 @@ require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
2
 
3
3
  include TZInfo
4
4
 
5
+ # Use send as a workaround for erroneous 'wrong number of arguments' errors with
6
+ # JRuby 9.0.5.0 when calling methods with Java implementations. See #114.
7
+ send(:using, TaintExt) if Module.const_defined?(:TaintExt)
8
+
5
9
  class TCCountry < Minitest::Test
6
10
  def setup
7
11
  @orig_data_source = DataSource.get
@@ -46,7 +50,7 @@ class TCCountry < Minitest::Test
46
50
  def test_get_tainted_loaded
47
51
  Country.get('GB')
48
52
 
49
- safe_test do
53
+ safe_test(:unavailable => :skip) do
50
54
  code = 'GB'.dup.taint
51
55
  assert(code.tainted?)
52
56
  country = Country.get(code)
@@ -65,7 +69,7 @@ class TCCountry < Minitest::Test
65
69
  end
66
70
 
67
71
  def test_get_tainted_not_previously_loaded
68
- safe_test do
72
+ safe_test(:unavailable => :skip) do
69
73
  code = 'GB'.dup.taint
70
74
  assert(code.tainted?)
71
75
  country = Country.get(code)
@@ -190,7 +194,6 @@ class TCCountry < Minitest::Test
190
194
  # If country gets reloaded for some reason, it needs to force a reload of
191
195
  # the country index.
192
196
 
193
- c = Country.get('US')
194
197
  assert_equal('US', Country.get('US').code)
195
198
 
196
199
  # Suppress redefined method warnings.
@@ -198,7 +201,6 @@ class TCCountry < Minitest::Test
198
201
  load 'tzinfo/country.rb'
199
202
  end
200
203
 
201
- c = Country.get('US')
202
204
  assert_equal('US', Country.get('US').code)
203
205
  end
204
206
 
@@ -17,6 +17,12 @@ class TCCountryTimezone < Minitest::Test
17
17
  ct = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
18
18
  assert_equal(Rational(2059, 40), ct.latitude)
19
19
  end
20
+
21
+ def test_latitude_after_freeze_new!
22
+ ct = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
23
+ ct.freeze
24
+ assert_equal(Rational(2059, 40), ct.latitude)
25
+ end
20
26
 
21
27
  def test_latitude_new
22
28
  ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
@@ -27,6 +33,12 @@ class TCCountryTimezone < Minitest::Test
27
33
  ct = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
28
34
  assert_equal(Rational(-5, 16), ct.longitude)
29
35
  end
36
+
37
+ def test_longitude_after_freeze_new!
38
+ ct = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
39
+ ct.freeze
40
+ assert_equal(Rational(-5, 16), ct.longitude)
41
+ end
30
42
 
31
43
  def test_longitude_new
32
44
  ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
@@ -37,6 +37,19 @@ class TCRubyCountryInfo < Minitest::Test
37
37
  assert_equal(['ZZ/TimezoneB', 'ZZ/TimezoneA', 'ZZ/TimezoneC', 'ZZ/TimezoneD'], ci.zone_identifiers)
38
38
  assert(ci.zone_identifiers.frozen?)
39
39
  end
40
+
41
+ def test_zone_identifiers_after_freeze
42
+ ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
43
+ c.timezone('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B')
44
+ c.timezone('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A')
45
+ c.timezone('ZZ/TimezoneC', -10, 3, -20, 7, 'C')
46
+ c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
47
+ end
48
+
49
+ ci.freeze
50
+
51
+ assert_equal(['ZZ/TimezoneB', 'ZZ/TimezoneA', 'ZZ/TimezoneC', 'ZZ/TimezoneD'], ci.zone_identifiers)
52
+ end
40
53
 
41
54
  def test_zones_empty
42
55
  ci = RubyCountryInfo.new('ZZ', 'Zzz') {|c| }
@@ -65,6 +78,23 @@ class TCRubyCountryInfo < Minitest::Test
65
78
  ci.zones)
66
79
  assert(ci.zones.frozen?)
67
80
  end
81
+
82
+ def test_zones_after_freeze
83
+ ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
84
+ c.timezone('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B')
85
+ c.timezone('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A')
86
+ c.timezone('ZZ/TimezoneC', -10, 3, -20, 7, 'C')
87
+ c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
88
+ end
89
+
90
+ ci.freeze
91
+
92
+ assert_equal([CountryTimezone.new!('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B'),
93
+ CountryTimezone.new!('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A'),
94
+ CountryTimezone.new!('ZZ/TimezoneC', -10, 3, -20, 7, 'C'),
95
+ CountryTimezone.new!('ZZ/TimezoneD', -10, 3, -20, 7)],
96
+ ci.zones)
97
+ end
68
98
 
69
99
  def test_deferred_evaluate
70
100
  block_called = false
@@ -2,11 +2,31 @@ require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
2
 
3
3
  include TZInfo
4
4
 
5
+ # Use send as a workaround for erroneous 'wrong number of arguments' errors with
6
+ # JRuby 9.0.5.0 when calling methods with Java implementations. See #114.
7
+ send(:using, TaintExt) if Module.const_defined?(:TaintExt)
8
+
5
9
  class TCRubyDataSource < Minitest::Test
6
10
  def setup
7
11
  @data_source = RubyDataSource.new
8
12
  end
9
13
 
14
+ def test_initialize_not_found
15
+ # A failure to load tzinfo/data in initialize will not cause an exception.
16
+ # Attempts to load data files will subsequently fail.
17
+ code = <<-EOF
18
+ begin
19
+ ds = TZInfo::RubyDataSource.new
20
+ puts 'Initialized'
21
+ ds.load_timezone_info('Europe/London')
22
+ rescue Exception => e
23
+ puts e.class
24
+ end
25
+ EOF
26
+
27
+ assert_sub_process_returns(['Initialized', 'TZInfo::InvalidTimezoneIdentifier'], code)
28
+ end
29
+
10
30
  def test_load_timezone_info_data
11
31
  info = @data_source.load_timezone_info('Europe/London')
12
32
  assert_kind_of(DataTimezoneInfo, info)
@@ -55,7 +75,9 @@ class TCRubyDataSource < Minitest::Test
55
75
  end
56
76
 
57
77
  def test_load_timezone_info_tainted
58
- safe_test do
78
+ skip_if_has_bug_14060
79
+
80
+ safe_test(:unavailable => :skip) do
59
81
  identifier = 'Europe/Amsterdam'.dup.taint
60
82
  assert(identifier.tainted?)
61
83
  info = @data_source.load_timezone_info(identifier)
@@ -65,6 +87,8 @@ class TCRubyDataSource < Minitest::Test
65
87
  end
66
88
 
67
89
  def test_load_timezone_info_tainted_and_frozen
90
+ skip_if_has_bug_14060
91
+
68
92
  safe_test do
69
93
  info = @data_source.load_timezone_info('Europe/Amsterdam'.dup.taint.freeze)
70
94
  assert_equal('Europe/Amsterdam', info.identifier)
@@ -119,7 +143,7 @@ class TCRubyDataSource < Minitest::Test
119
143
  end
120
144
 
121
145
  def test_load_country_info_tainted
122
- safe_test do
146
+ safe_test(:unavailable => :skip) do
123
147
  code = 'NL'.dup.taint
124
148
  assert(code.tainted?)
125
149
  info = @data_source.load_country_info(code)
@@ -4,6 +4,12 @@ require 'rational' unless defined?(Rational)
4
4
  include TZInfo
5
5
 
6
6
  class TCTimeOrDateTime < Minitest::Test
7
+ # Ruby 1.8.7 (built with GCC 8.3.0 on Ubuntu 19.04) fails to perform DateTime
8
+ # arithmetic operations correctly when sub-seconds are used. Detect this and
9
+ # disable the affected tests.
10
+ DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN = (DateTime.new(2019, 12, 22, 15, 0, Rational(1, 1000)) + Rational(1, 86400)).strftime('%Q') != '1577026801001'
11
+ puts "DateTime sub-second arithmetic is broken on this platform" if DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN
12
+
7
13
  def test_initialize_time
8
14
  assert_nothing_raised do
9
15
  TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000))
@@ -128,6 +134,11 @@ class TCTimeOrDateTime < Minitest::Test
128
134
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123),
129
135
  TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(7211239, 10000000))).to_time)
130
136
  end
137
+
138
+ def test_to_time_after_freeze
139
+ assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).freeze.to_time)
140
+ assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), TimeOrDateTime.new(1143214323).freeze.to_time)
141
+ end
131
142
 
132
143
  def test_to_datetime
133
144
  assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3),
@@ -157,6 +168,11 @@ class TCTimeOrDateTime < Minitest::Test
157
168
  assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721123, 1000000)),
158
169
  TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721123 + Rational(9, 10))).to_datetime)
159
170
  end
171
+
172
+ def test_to_datetime_after_freeze
173
+ assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).freeze.to_datetime)
174
+ assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), TimeOrDateTime.new(1143214323).freeze.to_datetime)
175
+ end
160
176
 
161
177
  def test_to_i
162
178
  assert_equal(1143214323,
@@ -172,6 +188,11 @@ class TCTimeOrDateTime < Minitest::Test
172
188
  assert_equal(1143214323,
173
189
  TimeOrDateTime.new('1143214323').to_i)
174
190
  end
191
+
192
+ def test_to_i_after_freeze
193
+ assert_equal(1143214323, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).freeze.to_i)
194
+ assert_equal(1143214323, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).freeze.to_i)
195
+ end
175
196
 
176
197
  def test_to_orig
177
198
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 3),
@@ -485,12 +506,12 @@ class TCTimeOrDateTime < Minitest::Test
485
506
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 4), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) + 1).to_orig)
486
507
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 4, 721000), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)) + 1).to_orig)
487
508
  assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) + 1).to_orig)
488
- assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) + 1).to_orig)
509
+ assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) + 1).to_orig) unless DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN
489
510
  assert_equal(1143214324, (TimeOrDateTime.new(1143214323) + 1).to_orig)
490
511
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 2), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) + (-1)).to_orig)
491
512
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 2, 721000), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)) + (-1)).to_orig)
492
513
  assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) + (-1)).to_orig)
493
- assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) + (-1)).to_orig)
514
+ assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) + (-1)).to_orig) unless DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN
494
515
  assert_equal(1143214322, (TimeOrDateTime.new(1143214323) + (-1)).to_orig)
495
516
  end
496
517
 
@@ -503,12 +524,12 @@ class TCTimeOrDateTime < Minitest::Test
503
524
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 2), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) - 1).to_orig)
504
525
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 2, 721000), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)) - 1).to_orig)
505
526
  assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) - 1).to_orig)
506
- assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) - 1).to_orig)
527
+ assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) - 1).to_orig) unless DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN
507
528
  assert_equal(1143214322, (TimeOrDateTime.new(1143214323) - 1).to_orig)
508
529
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 4), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) - (-1)).to_orig)
509
530
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 4, 721000), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)) - (-1)).to_orig)
510
531
  assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) - (-1)).to_orig)
511
- assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) - (-1)).to_orig)
532
+ assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) - (-1)).to_orig) unless DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN
512
533
  assert_equal(1143214324, (TimeOrDateTime.new(1143214323) - (-1)).to_orig)
513
534
  end
514
535
 
@@ -521,12 +542,12 @@ class TCTimeOrDateTime < Minitest::Test
521
542
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 4), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).add_with_convert(1).to_orig)
522
543
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 4, 721000), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)).add_with_convert(1).to_orig)
523
544
  assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).add_with_convert(1).to_orig)
524
- assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4 + Rational(721, 1000)), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).add_with_convert(1).to_orig)
545
+ assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4 + Rational(721, 1000)), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).add_with_convert(1).to_orig) unless DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN
525
546
  assert_equal(1143214324, TimeOrDateTime.new(1143214323).add_with_convert(1).to_orig)
526
547
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 2), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).add_with_convert(-1).to_orig)
527
548
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 2, 721000), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)).add_with_convert(-1).to_orig)
528
549
  assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).add_with_convert(-1).to_orig)
529
- assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2 + Rational(721, 1000)), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).add_with_convert(-1).to_orig)
550
+ assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2 + Rational(721, 1000)), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).add_with_convert(-1).to_orig) unless DATETIME_SUBSECOND_ARITHMETIC_IS_BROKEN
530
551
  assert_equal(1143214322, TimeOrDateTime.new(1143214323).add_with_convert(-1).to_orig)
531
552
 
532
553
  if RubyCoreSupport.time_supports_negative
@@ -2,6 +2,10 @@ require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
2
 
3
3
  include TZInfo
4
4
 
5
+ # Use send as a workaround for erroneous 'wrong number of arguments' errors with
6
+ # JRuby 9.0.5.0 when calling methods with Java implementations. See #114.
7
+ send(:using, TaintExt) if Module.const_defined?(:TaintExt)
8
+
5
9
  class TCTimezone < Minitest::Test
6
10
 
7
11
  class BlockCalled < StandardError
@@ -242,7 +246,7 @@ class TCTimezone < Minitest::Test
242
246
  def test_get_tainted_loaded
243
247
  Timezone.get('Europe/Andorra')
244
248
 
245
- safe_test do
249
+ safe_test(:unavailable => :skip) do
246
250
  identifier = 'Europe/Andorra'.dup.taint
247
251
  assert(identifier.tainted?)
248
252
  tz = Timezone.get(identifier)
@@ -261,7 +265,9 @@ class TCTimezone < Minitest::Test
261
265
  end
262
266
 
263
267
  def test_get_tainted_not_previously_loaded
264
- safe_test do
268
+ skip_if_has_bug_14060
269
+
270
+ safe_test(:unavailable => :skip) do
265
271
  identifier = 'Europe/Andorra'.dup.taint
266
272
  assert(identifier.tainted?)
267
273
  tz = Timezone.get(identifier)
@@ -271,6 +277,8 @@ class TCTimezone < Minitest::Test
271
277
  end
272
278
 
273
279
  def test_get_tainted_and_frozen_not_previously_loaded
280
+ skip_if_has_bug_14060
281
+
274
282
  safe_test do
275
283
  tz = Timezone.get('Europe/Amsterdam'.dup.taint.freeze)
276
284
  assert_equal('Europe/Amsterdam', tz.identifier)
@@ -1260,6 +1268,7 @@ class TCTimezone < Minitest::Test
1260
1268
  assert_equal('BST BST', tz.strftime('%Z %Z', dt))
1261
1269
  assert_equal('BST %Z %BST %%Z %%BST', tz.strftime('%Z %%Z %%%Z %%%%Z %%%%%Z', dt))
1262
1270
  assert_equal('+0100 +01:00 +01:00:00 +01 %::::z', tz.strftime('%z %:z %::z %:::z %::::z', dt))
1271
+ assert_equal('1153001522 %s %1153001522', tz.strftime('%s %%s %%%s', dt))
1263
1272
  end
1264
1273
 
1265
1274
  def test_strftime_time
@@ -1271,6 +1280,7 @@ class TCTimezone < Minitest::Test
1271
1280
  assert_equal('BST BST', tz.strftime('%Z %Z', t))
1272
1281
  assert_equal('BST %Z %BST %%Z %%BST', tz.strftime('%Z %%Z %%%Z %%%%Z %%%%%Z', t))
1273
1282
  assert_equal('+0100 +01:00 +01:00:00 +01 %::::z', tz.strftime('%z %:z %::z %:::z %::::z', t))
1283
+ assert_equal('1153001522 %s %1153001522', tz.strftime('%s %%s %%%s', t))
1274
1284
  end
1275
1285
 
1276
1286
  def test_strftime_int
@@ -1282,6 +1292,7 @@ class TCTimezone < Minitest::Test
1282
1292
  assert_equal('BST BST', tz.strftime('%Z %Z', i))
1283
1293
  assert_equal('BST %Z %BST %%Z %%BST', tz.strftime('%Z %%Z %%%Z %%%%Z %%%%%Z', i))
1284
1294
  assert_equal('+0100 +01:00 +01:00:00 +01 %::::z', tz.strftime('%z %:z %::z %:::z %::::z', i))
1295
+ assert_equal('1153001522 %s %1153001522', tz.strftime('%s %%s %%%s', i))
1285
1296
  end
1286
1297
 
1287
1298
  def test_get_missing_data_source
@@ -149,6 +149,13 @@ class TCTimezonePeriod < Minitest::Test
149
149
  assert_nil(p.local_end)
150
150
  assert_nil(p.local_end_time)
151
151
  end
152
+
153
+ def test_utc_total_offset_rational_after_freeze
154
+ o = TimezoneOffset.new(3600, 0, :TEST)
155
+ p = TimezonePeriod.new(nil, nil, o)
156
+ p.freeze
157
+ assert_equal(Rational(1, 24), p.utc_total_offset_rational)
158
+ end
152
159
 
153
160
  def test_dst
154
161
  p1 = TimezonePeriod.new(nil, nil, TimezoneOffset.new(-14400, 3600, :TEST))
@@ -88,6 +88,15 @@ class TCTimezoneProxy < Minitest::Test
88
88
  assert_same(Timezone.get('UTC'), proxy.canonical_zone)
89
89
  end
90
90
  end
91
+
92
+ def test_after_freeze
93
+ proxy = TimezoneProxy.new('Europe/London')
94
+ real = Timezone.get('Europe/London')
95
+ t = Time.utc(2017, 6, 1)
96
+ proxy.freeze
97
+ assert_equal('Europe/London', proxy.identifier)
98
+ assert_equal(real.utc_to_local(t), proxy.utc_to_local(t))
99
+ end
91
100
 
92
101
  def test_equals
93
102
  assert_equal(true, TimezoneProxy.new('Europe/London') == TimezoneProxy.new('Europe/London'))
@@ -68,6 +68,13 @@ class TCTimezoneTransition < Minitest::Test
68
68
  assert(TimeOrDateTime.new(DateTime.new(2006, 5, 30, 1, 31, 20)).eql?(t2.local_end_at))
69
69
  assert(TimeOrDateTime.new(Time.utc(2006, 5, 30, 1, 31, 20)).eql?(t3.local_end_at))
70
70
  end
71
+
72
+ def test_local_end_at_after_freeze
73
+ t = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
74
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
75
+ t.freeze
76
+ assert(TimeOrDateTime.new(1148952680).eql?(t.local_end_at))
77
+ end
71
78
 
72
79
  def test_local_end
73
80
  t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
@@ -107,6 +114,13 @@ class TCTimezoneTransition < Minitest::Test
107
114
  assert(TimeOrDateTime.new(DateTime.new(2006, 5, 30, 2, 31, 20)).eql?(t2.local_start_at))
108
115
  assert(TimeOrDateTime.new(Time.utc(2006, 5, 30, 2, 31, 20)).eql?(t3.local_start_at))
109
116
  end
117
+
118
+ def test_local_start_at_after_freeze
119
+ t = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
120
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
121
+ t.freeze
122
+ assert(TimeOrDateTime.new(1148956280).eql?(t.local_start_at))
123
+ end
110
124
 
111
125
  def test_local_start
112
126
  t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
@@ -70,6 +70,17 @@ class TCTimezoneTransitionDefinition < Minitest::Test
70
70
  assert(TimeOrDateTime.new(DateTime.new(2038, 1, 19, 3, 14, 8)).eql?(t.at))
71
71
  end
72
72
  end
73
+
74
+ def test_at_after_freeze
75
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
76
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
77
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
78
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
79
+ t1.freeze
80
+ t2.freeze
81
+ assert(TimeOrDateTime.new(1148949080).eql?(t1.at))
82
+ assert(TimeOrDateTime.new(DateTime.new(2006, 5, 30, 0, 31, 20)).eql?(t2.at))
83
+ end
73
84
 
74
85
  def test_eql_timestamp
75
86
  t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
@@ -359,7 +359,17 @@ class TCTransitionDataTimezoneInfo < Minitest::Test
359
359
  assert_equal([t1,t2,t3,t4,t5], dti.transitions_up_to(DateTime.new(2011,10,1,1,0,Rational(DATETIME_RESOLUTION,1000000))))
360
360
  assert_equal([t1,t2,t3,t4,t5], dti.transitions_up_to(DateTime.new(2011,10,1,1,0,1), DateTime.new(2010,4,1,1,0,0)))
361
361
  assert_equal([t2,t3,t4,t5], dti.transitions_up_to(DateTime.new(2011,10,1,1,0,1), DateTime.new(2010,4,1,1,0,1)))
362
- assert_equal([t2,t3,t4,t5], dti.transitions_up_to(DateTime.new(2011,10,1,1,0,1), DateTime.new(2010,4,1,1,0,Rational(DATETIME_RESOLUTION,1000000))))
362
+
363
+ # Ruby 1.8.7 (built with GCC 8.3.0 on Ubuntu 19.04) fails to perform
364
+ # DateTime comparisons correctly when sub-seconds are used.
365
+ to = DateTime.new(2011,10,1,1,0,1)
366
+ from = DateTime.new(2010,4,1,1,0,Rational(DATETIME_RESOLUTION,1000000))
367
+ if to > from
368
+ assert_equal([t2,t3,t4,t5], dti.transitions_up_to(to, from))
369
+ else
370
+ puts "This platform does not consider the DateTime #{to.strftime('%Y-%m-%d %H:%m:%S.%N')} to be later than the DateTime #{from.strftime('%Y-%m-%d %H:%m:%S.%N')}"
371
+ end
372
+
363
373
  assert_equal([t5], dti.transitions_up_to(DateTime.new(2015,1,1,0,0,0), DateTime.new(2011,10,1,1,0,0)))
364
374
  assert_equal([], dti.transitions_up_to(DateTime.new(2015,1,1,0,0,0), DateTime.new(2011,10,1,1,0,1)))
365
375
  end
@@ -35,6 +35,20 @@ class TCZoneinfoCountryInfo < Minitest::Test
35
35
  assert(!ci.zones.equal?(zones))
36
36
  assert(!zones.frozen?)
37
37
  end
38
+
39
+ def test_zone_identifiers_after_freeze
40
+ zones = [
41
+ CountryTimezone.new('ZZ/TimezoneB', Rational(1, 2), Rational(1, 2), 'Timezone B'),
42
+ CountryTimezone.new('ZZ/TimezoneA', Rational(1, 4), Rational(1, 4), 'Timezone A'),
43
+ CountryTimezone.new('ZZ/TimezoneC', Rational(-10, 3), Rational(-20, 7), 'C'),
44
+ CountryTimezone.new('ZZ/TimezoneD', Rational(-10, 3), Rational(-20, 7))
45
+ ]
46
+
47
+ ci = ZoneinfoCountryInfo.new('ZZ', 'Zzz', zones)
48
+ ci.freeze
49
+
50
+ assert_equal(['ZZ/TimezoneB', 'ZZ/TimezoneA', 'ZZ/TimezoneC', 'ZZ/TimezoneD'], ci.zone_identifiers)
51
+ end
38
52
 
39
53
  def test_zones_empty
40
54
  ci = ZoneinfoCountryInfo.new('ZZ', 'Zzz', [])
@@ -7,6 +7,15 @@ require 'tmpdir'
7
7
 
8
8
  include TZInfo
9
9
 
10
+ # Use send as a workaround for an issue on JRuby 9.2.9.0 where using the
11
+ # refinement causes calls to RubyCoreSupport.file_open to fail to pass the block
12
+ # parameter.
13
+ #
14
+ # https://travis-ci.org/tzinfo/tzinfo/jobs/628812051#L1931
15
+ # https://github.com/jruby/jruby/issues/6009
16
+ send(:using, TZInfo::RubyCoreSupport::UntaintExt) if TZInfo::RubyCoreSupport.const_defined?(:UntaintExt)
17
+ send(:using, TaintExt) if Module.const_defined?(:TaintExt)
18
+
10
19
  class TCZoneinfoDataSource < Minitest::Test
11
20
  ZONEINFO_DIR = File.join(File.expand_path(File.dirname(__FILE__)), 'zoneinfo').untaint
12
21
 
@@ -653,7 +662,7 @@ class TCZoneinfoDataSource < Minitest::Test
653
662
  end
654
663
 
655
664
  def test_load_timezone_info_tainted
656
- safe_test do
665
+ safe_test(:unavailable => :skip) do
657
666
  identifier = 'Europe/Amsterdam'.dup.taint
658
667
  assert(identifier.tainted?)
659
668
  info = @data_source.load_timezone_info(identifier)
@@ -840,7 +849,7 @@ class TCZoneinfoDataSource < Minitest::Test
840
849
  end
841
850
 
842
851
  def test_load_country_info_tainted
843
- safe_test do
852
+ safe_test(:unavailable => :skip) do
844
853
  code = 'NL'.dup.taint
845
854
  assert(code.tainted?)
846
855
  info = @data_source.load_country_info(code)