tzinfo 1.1.0 → 1.2.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 (77) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CHANGES.md +33 -0
  5. data/LICENSE +1 -1
  6. data/README.md +36 -31
  7. data/Rakefile +17 -23
  8. data/lib/tzinfo.rb +0 -22
  9. data/lib/tzinfo/country.rb +3 -22
  10. data/lib/tzinfo/country_index_definition.rb +0 -22
  11. data/lib/tzinfo/country_info.rb +0 -22
  12. data/lib/tzinfo/country_timezone.rb +46 -31
  13. data/lib/tzinfo/data_source.rb +7 -24
  14. data/lib/tzinfo/data_timezone.rb +7 -22
  15. data/lib/tzinfo/data_timezone_info.rb +0 -22
  16. data/lib/tzinfo/info_timezone.rb +0 -22
  17. data/lib/tzinfo/linked_timezone.rb +7 -22
  18. data/lib/tzinfo/linked_timezone_info.rb +0 -22
  19. data/lib/tzinfo/offset_rationals.rb +0 -22
  20. data/lib/tzinfo/ruby_core_support.rb +14 -22
  21. data/lib/tzinfo/ruby_country_info.rb +3 -25
  22. data/lib/tzinfo/ruby_data_source.rb +1 -23
  23. data/lib/tzinfo/time_or_datetime.rb +13 -27
  24. data/lib/tzinfo/timezone.rb +51 -23
  25. data/lib/tzinfo/timezone_definition.rb +0 -22
  26. data/lib/tzinfo/timezone_index_definition.rb +0 -22
  27. data/lib/tzinfo/timezone_info.rb +0 -22
  28. data/lib/tzinfo/timezone_offset.rb +0 -22
  29. data/lib/tzinfo/timezone_period.rb +1 -23
  30. data/lib/tzinfo/timezone_proxy.rb +6 -23
  31. data/lib/tzinfo/timezone_transition.rb +2 -24
  32. data/lib/tzinfo/timezone_transition_definition.rb +1 -23
  33. data/lib/tzinfo/transition_data_timezone_info.rb +0 -22
  34. data/lib/tzinfo/zoneinfo_country_info.rb +1 -23
  35. data/lib/tzinfo/zoneinfo_data_source.rb +177 -61
  36. data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -22
  37. data/test/tc_country.rb +6 -24
  38. data/test/tc_country_index_definition.rb +1 -23
  39. data/test/tc_country_info.rb +1 -23
  40. data/test/tc_country_timezone.rb +82 -62
  41. data/test/tc_data_source.rb +22 -24
  42. data/test/tc_data_timezone.rb +12 -24
  43. data/test/tc_data_timezone_info.rb +1 -23
  44. data/test/tc_info_timezone.rb +1 -23
  45. data/test/tc_linked_timezone.rb +37 -24
  46. data/test/tc_linked_timezone_info.rb +1 -23
  47. data/test/tc_offset_rationals.rb +1 -23
  48. data/test/tc_ruby_core_support.rb +84 -33
  49. data/test/tc_ruby_country_info.rb +5 -27
  50. data/test/tc_ruby_data_source.rb +1 -23
  51. data/test/tc_time_or_datetime.rb +44 -36
  52. data/test/tc_timezone.rb +32 -48
  53. data/test/tc_timezone_definition.rb +1 -23
  54. data/test/tc_timezone_index_definition.rb +1 -23
  55. data/test/tc_timezone_info.rb +1 -23
  56. data/test/tc_timezone_london.rb +1 -23
  57. data/test/tc_timezone_melbourne.rb +1 -23
  58. data/test/tc_timezone_new_york.rb +1 -23
  59. data/test/tc_timezone_offset.rb +1 -23
  60. data/test/tc_timezone_period.rb +5 -27
  61. data/test/tc_timezone_proxy.rb +34 -28
  62. data/test/tc_timezone_transition.rb +1 -23
  63. data/test/tc_timezone_transition_definition.rb +1 -23
  64. data/test/tc_timezone_utc.rb +1 -23
  65. data/test/tc_transition_data_timezone_info.rb +3 -25
  66. data/test/tc_zoneinfo_country_info.rb +13 -35
  67. data/test/tc_zoneinfo_data_source.rb +358 -34
  68. data/test/tc_zoneinfo_timezone_info.rb +3 -27
  69. data/test/test_utils.rb +26 -30
  70. data/test/ts_all.rb +0 -22
  71. data/test/ts_all_ruby.rb +0 -22
  72. data/test/ts_all_zoneinfo.rb +0 -22
  73. data/test/tzinfo-data/tzinfo/data.rb +0 -22
  74. data/test/tzinfo-data/tzinfo/data/version.rb +0 -22
  75. data/tzinfo.gemspec +2 -2
  76. metadata +80 -80
  77. metadata.gz.sig +1 -3
@@ -1,30 +1,8 @@
1
- #--
2
- # Copyright (c) 2013 Philip Ross
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #++
22
-
23
1
  require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
24
2
 
25
3
  include TZInfo
26
4
 
27
- class TCDataTimezoneInfo < Test::Unit::TestCase
5
+ class TCDataTimezoneInfo < Minitest::Test
28
6
 
29
7
  def test_identifier
30
8
  ti = DataTimezoneInfo.new('Test/Zone')
@@ -1,30 +1,8 @@
1
- #--
2
- # Copyright (c) 2006-2013 Philip Ross
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #++
22
-
23
1
  require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
24
2
 
25
3
  include TZInfo
26
4
 
27
- class TCInfoTimezone < Test::Unit::TestCase
5
+ class TCInfoTimezone < Minitest::Test
28
6
 
29
7
  class TestInfoTimezone < InfoTimezone
30
8
  attr_reader :setup_info
@@ -1,30 +1,8 @@
1
- #--
2
- # Copyright (c) 2006-2013 Philip Ross
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #++
22
-
23
1
  require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
24
2
 
25
3
  include TZInfo
26
4
 
27
- class TCLinkedTimezone < Test::Unit::TestCase
5
+ class TCLinkedTimezone < Minitest::Test
28
6
 
29
7
  class TestTimezone < Timezone
30
8
  attr_reader :utc_period
@@ -62,6 +40,10 @@ class TCLinkedTimezone < Test::Unit::TestCase
62
40
  @up_to_transitions
63
41
  end
64
42
 
43
+ def canonical_zone
44
+ self
45
+ end
46
+
65
47
  private
66
48
  def setup(identifier, no_local_periods)
67
49
  @identifier = identifier
@@ -84,7 +66,10 @@ class TCLinkedTimezone < Test::Unit::TestCase
84
66
  raise InvalidTimezoneIdentifier, 'Invalid identifier' if identifier == 'Invalid/Identifier'
85
67
 
86
68
  @timezones ||= {}
87
- @timezones[identifier] ||= TestTimezone.new(identifier, identifier == 'Test/No/Local')
69
+ @timezones[identifier] ||=
70
+ identifier == 'Test/Recursive/Linked' ?
71
+ LinkedTimezone.new(LinkedTimezoneInfo.new(identifier, 'Test/Recursive/Data')) :
72
+ TestTimezone.new(identifier, identifier == 'Test/No/Local')
88
73
  end
89
74
  end
90
75
  end
@@ -139,4 +124,32 @@ class TCLinkedTimezone < Test::Unit::TestCase
139
124
  assert_same(utc_to, linked_tz.utc_to)
140
125
  assert_same(utc_from, linked_tz.utc_from)
141
126
  end
127
+
128
+ def test_canonical_identifier
129
+ tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked'))
130
+ assert_equal('Test/Linked', tz.canonical_identifier)
131
+ end
132
+
133
+ def test_canonical_identifier_recursive
134
+ # Recursive links are not currently used in the Time Zone database, but
135
+ # will be supported by TZInfo.
136
+
137
+ tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Recursive/Linked'))
138
+ assert_equal('Test/Recursive/Data', tz.canonical_identifier)
139
+ end
140
+
141
+ def test_canonical_zone
142
+ tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked'))
143
+ linked_tz = Timezone.get('Test/Linked')
144
+ assert_same(linked_tz, tz.canonical_zone)
145
+ end
146
+
147
+ def test_canonical_zone_recursive
148
+ # Recursive links are not currently used in the Time Zone database, but
149
+ # will be supported by TZInfo.
150
+
151
+ tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Recursive/Linked'))
152
+ linked_tz = Timezone.get('Test/Recursive/Data')
153
+ assert_same(linked_tz, tz.canonical_zone)
154
+ end
142
155
  end
@@ -1,30 +1,8 @@
1
- #--
2
- # Copyright (c) 2006-2013 Philip Ross
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #++
22
-
23
1
  require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
24
2
 
25
3
  include TZInfo
26
4
 
27
- class TCLinkedTimezoneInfo < Test::Unit::TestCase
5
+ class TCLinkedTimezoneInfo < Minitest::Test
28
6
 
29
7
  def test_identifier
30
8
  lti = LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked')
@@ -1,30 +1,8 @@
1
- #--
2
- # Copyright (c) 2006-2013 Philip Ross
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #++
22
-
23
1
  require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
24
2
 
25
3
  include TZInfo
26
4
 
27
- class TCOffsetRationals < Test::Unit::TestCase
5
+ class TCOffsetRationals < Minitest::Test
28
6
  def test_rational_for_offset
29
7
  [0,1,2,3,4,-1,-2,-3,-4,30*60,-30*60,61*60,-61*60,14*60*60,-14*60*60,20*60*60,-20*60*60].each {|seconds|
30
8
  assert_equal(Rational(seconds, 86400), OffsetRationals.rational_for_offset(seconds))
@@ -1,62 +1,40 @@
1
1
  # encoding: UTF-8
2
2
 
3
- #--
4
- # Copyright (c) 2008-2013 Philip Ross
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
- #++
24
-
25
3
  require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
26
4
 
27
5
  include TZInfo
28
6
 
29
- class TCRubyCoreSupport < Test::Unit::TestCase
7
+ class TCRubyCoreSupport < Minitest::Test
30
8
  def test_rational_new!
31
9
  assert_equal(Rational(3,4), RubyCoreSupport.rational_new!(3,4))
32
10
  end
33
11
 
34
12
  def test_datetime_new!
35
13
  assert_equal(DateTime.new(2008,10,5,12,0,0, 0, Date::ITALY), RubyCoreSupport.datetime_new!(2454745,0,2299161))
36
- assert_equal(DateTime.new(2008,10,6,12,0,0, 1, Date::ITALY), RubyCoreSupport.datetime_new!(2454745,1,2299161))
14
+ assert_equal(DateTime.new(2008,10,5,13,0,0, Rational(1, 24), Date::ITALY), RubyCoreSupport.datetime_new!(2454745,Rational(1, 24),2299161))
37
15
 
38
16
  assert_equal(DateTime.new(2008,10,5,20,30,0, 0, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(117827777, 48), 0, 2299161))
39
- assert_equal(DateTime.new(2008,10,6,20,30,0, 1, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(117827777, 48), 1, 2299161))
17
+ assert_equal(DateTime.new(2008,10,5,21,30,0, Rational(1, 24), Date::ITALY), RubyCoreSupport.datetime_new!(Rational(117827777, 48), Rational(1, 24), 2299161))
40
18
 
41
19
  assert_equal(DateTime.new(2008,10,6,6,26,21, 0, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(70696678127,28800), 0, 2299161))
42
- assert_equal(DateTime.new(2008,10,7,6,26,21, 1, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(70696678127, 28800), 1, 2299161))
20
+ assert_equal(DateTime.new(2008,10,6,7,26,21, Rational(1, 24), Date::ITALY), RubyCoreSupport.datetime_new!(Rational(70696678127, 28800), Rational(1, 24), 2299161))
43
21
 
44
22
  assert_equal(DateTime.new(-4712,1,1,12,0,0, 0, Date::ITALY), RubyCoreSupport.datetime_new!(0, 0, 2299161))
45
- assert_equal(DateTime.new(-4712,1,2,12,0,0, 1, Date::ITALY), RubyCoreSupport.datetime_new!(0, 1, 2299161))
23
+ assert_equal(DateTime.new(-4712,1,1,13,0,0, Rational(1, 24), Date::ITALY), RubyCoreSupport.datetime_new!(0, Rational(1, 24), 2299161))
46
24
 
47
- assert_equal(DateTime.new(-4713,12,31,10,58,59, 0, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(-90061, 86400), 0, 2299161))
48
- assert_equal(DateTime.new(-4712,1,1,10,58,59, 1, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(-90061, 86400), 1, 2299161))
25
+ assert_equal(DateTime.new(-4713,12,31,23,58,59, 0, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(-43261, 86400), 0, 2299161))
26
+ assert_equal(DateTime.new(-4712,1,1,0,58,59, Rational(1, 24), Date::ITALY), RubyCoreSupport.datetime_new!(Rational(-43261, 86400), Rational(1, 24), 2299161))
49
27
 
50
- assert_equal(DateTime.new(-4713,12,30,10,58,59, 0, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(-176461, 86400), 0, 2299161))
51
- assert_equal(DateTime.new(-4713,12,31,10,58,59, 1, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(-176461, 86400), 1, 2299161))
28
+ assert_equal(DateTime.new(-4713,12,30,23,58,59, 0, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(-129661, 86400), 0, 2299161))
29
+ assert_equal(DateTime.new(-4713,12,31,0,58,59, Rational(1, 24), Date::ITALY), RubyCoreSupport.datetime_new!(Rational(-129661, 86400), Rational(1, 24), 2299161))
52
30
  end
53
31
 
54
32
  def test_datetime_new
55
33
  assert_equal(DateTime.new(2012, 12, 31, 23, 59, 59, 0, Date::ITALY), RubyCoreSupport.datetime_new(2012, 12, 31, 23, 59, 59, 0, Date::ITALY))
56
- assert_equal(DateTime.new(2013, 2, 6, 23, 2, 36, 1, Date::ITALY), RubyCoreSupport.datetime_new(2013, 2, 6, 23, 2, 36, 1, Date::ITALY))
34
+ assert_equal(DateTime.new(2013, 2, 6, 23, 2, 36, Rational(1, 24), Date::ITALY), RubyCoreSupport.datetime_new(2013, 2, 6, 23, 2, 36, Rational(1,24), Date::ITALY))
57
35
 
58
36
  assert_equal(DateTime.new(2012, 12, 31, 23, 59, 59, 0, Date::ITALY) + Rational(1, 86400000), RubyCoreSupport.datetime_new(2012, 12, 31, 23, 59, 59 + Rational(1, 1000), 0, Date::ITALY))
59
- assert_equal(DateTime.new(2001, 10, 12, 12, 22, 59, 1, Date::ITALY) + Rational(501, 86400000), RubyCoreSupport.datetime_new(2001, 10, 12, 12, 22, 59 + Rational(501, 1000), 1, Date::ITALY))
37
+ assert_equal(DateTime.new(2001, 10, 12, 12, 22, 59, Rational(1, 24), Date::ITALY) + Rational(501, 86400000), RubyCoreSupport.datetime_new(2001, 10, 12, 12, 22, 59 + Rational(501, 1000), Rational(1, 24), Date::ITALY))
60
38
  end
61
39
 
62
40
  def test_time_supports_negative
@@ -114,4 +92,77 @@ class TCRubyCoreSupport < Test::Unit::TestCase
114
92
  assert_equal('©', s)
115
93
  end
116
94
  end
95
+
96
+ begin
97
+ SUPPORTS_ENCODING = !!Encoding
98
+ rescue NameError
99
+ SUPPORTS_ENCODING = false
100
+ end
101
+
102
+ def check_open_file_test_file_bytes(test_file)
103
+ if SUPPORTS_ENCODING
104
+ File.open(test_file, 'r') do |file|
105
+ file.binmode
106
+ data = file.read(2)
107
+ refute_nil(data)
108
+ assert_equal(2, data.length)
109
+ bytes = data.unpack('C2')
110
+ assert_equal(0xC2, bytes[0])
111
+ assert_equal(0xA9, bytes[1])
112
+ end
113
+ end
114
+ end
115
+
116
+ def check_open_file_test_file_content(file)
117
+ content = file.gets
118
+ refute_nil(content)
119
+ content.chomp!
120
+
121
+ if SUPPORTS_ENCODING
122
+ assert_equal('UTF-8', content.encoding.name)
123
+ assert_equal(1, content.length)
124
+ assert_equal(2, content.bytesize)
125
+ assert_equal('©', content)
126
+ else
127
+ assert_equal('x', content)
128
+ end
129
+ end
130
+
131
+ def test_open_file
132
+ Dir.mktmpdir('tzinfo_test') do |dir|
133
+ test_file = File.join(dir, 'test.txt')
134
+
135
+ file = RubyCoreSupport.open_file(test_file, 'w', :external_encoding => 'UTF-8')
136
+ begin
137
+ file.puts(SUPPORTS_ENCODING ? '©' : 'x')
138
+ ensure
139
+ file.close
140
+ end
141
+
142
+ check_open_file_test_file_bytes(test_file)
143
+
144
+ file = RubyCoreSupport.open_file(test_file, 'r', :external_encoding => 'UTF-8', :internal_encoding => 'UTF-8')
145
+ begin
146
+ check_open_file_test_file_content(file)
147
+ ensure
148
+ file.close
149
+ end
150
+ end
151
+ end
152
+
153
+ def test_open_file_block
154
+ Dir.mktmpdir('tzinfo_test') do |dir|
155
+ test_file = File.join(dir, 'test.txt')
156
+
157
+ RubyCoreSupport.open_file(test_file, 'w', :external_encoding => 'UTF-8') do |file|
158
+ file.puts(SUPPORTS_ENCODING ? '©' : 'x')
159
+ end
160
+
161
+ check_open_file_test_file_bytes(test_file)
162
+
163
+ RubyCoreSupport.open_file(test_file, 'r', :external_encoding => 'UTF-8', :internal_encoding => 'UTF-8') do |file|
164
+ check_open_file_test_file_content(file)
165
+ end
166
+ end
167
+ end
117
168
  end
@@ -1,30 +1,8 @@
1
- #--
2
- # Copyright (c) 2006-2013 Philip Ross
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #++
22
-
23
1
  require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
24
2
 
25
3
  include TZInfo
26
4
 
27
- class TCRubyCountryInfo < Test::Unit::TestCase
5
+ class TCRubyCountryInfo < Minitest::Test
28
6
 
29
7
  def test_code
30
8
  ci = RubyCountryInfo.new('ZZ', 'Zzz') {|c| }
@@ -80,10 +58,10 @@ class TCRubyCountryInfo < Test::Unit::TestCase
80
58
  c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
81
59
  end
82
60
 
83
- assert_equal([CountryTimezone.new('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B'),
84
- CountryTimezone.new('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A'),
85
- CountryTimezone.new('ZZ/TimezoneC', -10, 3, -20, 7, 'C'),
86
- CountryTimezone.new('ZZ/TimezoneD', -10, 3, -20, 7)],
61
+ assert_equal([CountryTimezone.new!('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B'),
62
+ CountryTimezone.new!('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A'),
63
+ CountryTimezone.new!('ZZ/TimezoneC', -10, 3, -20, 7, 'C'),
64
+ CountryTimezone.new!('ZZ/TimezoneD', -10, 3, -20, 7)],
87
65
  ci.zones)
88
66
  assert(ci.zones.frozen?)
89
67
  end
@@ -1,30 +1,8 @@
1
- #--
2
- # Copyright (c) 2012-2013 Philip Ross
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #++
22
-
23
1
  require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
24
2
 
25
3
  include TZInfo
26
4
 
27
- class TCRubyDataSource < Test::Unit::TestCase
5
+ class TCRubyDataSource < Minitest::Test
28
6
  def setup
29
7
  @data_source = RubyDataSource.new
30
8
  end
@@ -1,31 +1,9 @@
1
- #--
2
- # Copyright (c) 2006-2013 Philip Ross
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the "Software"), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- # THE SOFTWARE.
21
- #++
22
-
23
1
  require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
24
- require 'rational'
2
+ require 'rational' unless defined?(Rational)
25
3
 
26
4
  include TZInfo
27
5
 
28
- class TCTimeOrDateTime < Test::Unit::TestCase
6
+ class TCTimeOrDateTime < Minitest::Test
29
7
  def test_initialize_time
30
8
  assert_nothing_raised do
31
9
  TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000))
@@ -37,6 +15,7 @@ class TCTimeOrDateTime < Test::Unit::TestCase
37
15
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), tdt.to_time)
38
16
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), tdt.to_orig)
39
17
  assert(tdt.to_time.utc?)
18
+ assert(tdt.to_orig.utc?)
40
19
  end
41
20
 
42
21
  def test_intialize_time_local_usec
@@ -44,6 +23,7 @@ class TCTimeOrDateTime < Test::Unit::TestCase
44
23
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123), tdt.to_time)
45
24
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123), tdt.to_orig)
46
25
  assert(tdt.to_time.utc?)
26
+ assert(tdt.to_orig.utc?)
47
27
  end
48
28
 
49
29
  if Time.utc(2013, 1, 1).respond_to?(:nsec)
@@ -52,6 +32,28 @@ class TCTimeOrDateTime < Test::Unit::TestCase
52
32
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123 + Rational(456,1000)), tdt.to_time)
53
33
  assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123 + Rational(456,1000)), tdt.to_orig)
54
34
  assert(tdt.to_time.utc?)
35
+ assert(tdt.to_orig.utc?)
36
+ end
37
+ end
38
+
39
+ def test_initialize_time_utc_local
40
+ # Check that local Time instances on systems using UTC as the system
41
+ # time zone are still converted to UTC Time instances.
42
+
43
+ # Note that this will only test will only work correctly on platforms where
44
+ # setting the TZ environment variable has an effect. If setting TZ has no
45
+ # effect, then this test will still pass.
46
+
47
+ old_tz = ENV['TZ']
48
+ begin
49
+ ENV['TZ'] = 'UTC'
50
+ tdt = TimeOrDateTime.new(Time.local(2014, 1, 11, 17, 18, 41))
51
+ assert_equal(Time.utc(2014, 1, 11, 17, 18, 41), tdt.to_time)
52
+ assert_equal(Time.utc(2014, 1, 11, 17, 18, 41), tdt.to_orig)
53
+ assert(tdt.to_time.utc?)
54
+ assert(tdt.to_orig.utc?)
55
+ ensure
56
+ ENV['TZ'] = old_tz
55
57
  end
56
58
  end
57
59
 
@@ -281,9 +283,9 @@ class TCTimeOrDateTime < Test::Unit::TestCase
281
283
  assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500001)))
282
284
  assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)))
283
285
  assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 499999)))
284
- assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500001)))
286
+ assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000 + DATETIME_RESOLUTION)))
285
287
  assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)))
286
- assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 499999)))
288
+ assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000 - DATETIME_RESOLUTION)))
287
289
  end
288
290
 
289
291
  def test_compare_timeordatetime_datetime
@@ -305,12 +307,12 @@ class TCTimeOrDateTime < Test::Unit::TestCase
305
307
  assert_equal(1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 2)))
306
308
  assert_equal(1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)))
307
309
 
308
- assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500001, 1000000))))
310
+ assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 + DATETIME_RESOLUTION, 1000000))))
309
311
  assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))))
310
- assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(499999, 1000000))))
311
- assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500001, 1000000))))
312
+ assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 - DATETIME_RESOLUTION, 1000000))))
313
+ assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 + DATETIME_RESOLUTION, 1000000))))
312
314
  assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))))
313
- assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(499999, 1000000))))
315
+ assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 - DATETIME_RESOLUTION, 1000000))))
314
316
  end
315
317
 
316
318
  def test_compare_timeordatetime_timestamp
@@ -355,9 +357,9 @@ class TCTimeOrDateTime < Test::Unit::TestCase
355
357
  assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> Time.utc(2006, 3, 24, 15, 32, 3, 500001))
356
358
  assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> Time.utc(2006, 3, 24, 15, 32, 3, 500000))
357
359
  assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> Time.utc(2006, 3, 24, 15, 32, 3, 499999))
358
- assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> Time.utc(2006, 3, 24, 15, 32, 3, 500001))
360
+ assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> Time.utc(2006, 3, 24, 15, 32, 3, 500000 + DATETIME_RESOLUTION))
359
361
  assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> Time.utc(2006, 3, 24, 15, 32, 3, 500000))
360
- assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> Time.utc(2006, 3, 24, 15, 32, 3, 499999))
362
+ assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> Time.utc(2006, 3, 24, 15, 32, 3, 500000 - DATETIME_RESOLUTION))
361
363
  end
362
364
 
363
365
  def test_compare_datetime
@@ -379,12 +381,12 @@ class TCTimeOrDateTime < Test::Unit::TestCase
379
381
  assert_equal(1, TimeOrDateTime.new(1143214323) <=> DateTime.new(2006, 3, 24, 15, 32, 2))
380
382
  assert_equal(1, TimeOrDateTime.new(1143214323) <=> DateTime.new(1960, 3, 24, 15, 32, 3))
381
383
 
382
- assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500001, 1000000)))
384
+ assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 + DATETIME_RESOLUTION, 1000000)))
383
385
  assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000)))
384
- assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(499999, 1000000)))
385
- assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500001, 1000000)))
386
+ assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 500000)) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 - DATETIME_RESOLUTION, 1000000)))
387
+ assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 + DATETIME_RESOLUTION, 1000000)))
386
388
  assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000)))
387
- assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(499999, 1000000)))
389
+ assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000, 1000000))) <=> DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(500000 - DATETIME_RESOLUTION, 1000000)))
388
390
  end
389
391
 
390
392
  def test_compare_timestamp
@@ -427,6 +429,12 @@ class TCTimeOrDateTime < Test::Unit::TestCase
427
429
  assert_equal(1, TimeOrDateTime.new(1143214323) <=> '1111678323')
428
430
  end
429
431
 
432
+ def test_compare_non_comparable
433
+ assert_nil(TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> Object.new)
434
+ assert_nil(TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> Object.new)
435
+ assert_nil(TimeOrDateTime.new(1143214323) <=> Object.new)
436
+ end
437
+
430
438
  def test_eql
431
439
  assert_equal(true, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3))))
432
440
  assert_equal(false, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3))))