tzinfo 1.2.6 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -1
  4. data/.yardopts +3 -0
  5. data/CHANGES.md +482 -380
  6. data/LICENSE +12 -12
  7. data/README.md +368 -114
  8. data/lib/tzinfo.rb +64 -29
  9. data/lib/tzinfo/country.rb +141 -129
  10. data/lib/tzinfo/country_timezone.rb +70 -112
  11. data/lib/tzinfo/data_source.rb +389 -144
  12. data/lib/tzinfo/data_sources.rb +8 -0
  13. data/lib/tzinfo/data_sources/constant_offset_data_timezone_info.rb +56 -0
  14. data/lib/tzinfo/data_sources/country_info.rb +42 -0
  15. data/lib/tzinfo/data_sources/data_timezone_info.rb +91 -0
  16. data/lib/tzinfo/data_sources/linked_timezone_info.rb +33 -0
  17. data/lib/tzinfo/data_sources/ruby_data_source.rb +143 -0
  18. data/lib/tzinfo/data_sources/timezone_info.rb +47 -0
  19. data/lib/tzinfo/data_sources/transitions_data_timezone_info.rb +214 -0
  20. data/lib/tzinfo/data_sources/zoneinfo_data_source.rb +575 -0
  21. data/lib/tzinfo/data_sources/zoneinfo_reader.rb +286 -0
  22. data/lib/tzinfo/data_timezone.rb +33 -47
  23. data/lib/tzinfo/datetime_with_offset.rb +153 -0
  24. data/lib/tzinfo/format1.rb +10 -0
  25. data/lib/tzinfo/format1/country_definer.rb +17 -0
  26. data/lib/tzinfo/format1/country_index_definition.rb +64 -0
  27. data/lib/tzinfo/format1/timezone_definer.rb +64 -0
  28. data/lib/tzinfo/format1/timezone_definition.rb +39 -0
  29. data/lib/tzinfo/format1/timezone_index_definition.rb +77 -0
  30. data/lib/tzinfo/format2.rb +10 -0
  31. data/lib/tzinfo/format2/country_definer.rb +68 -0
  32. data/lib/tzinfo/format2/country_index_definer.rb +68 -0
  33. data/lib/tzinfo/format2/country_index_definition.rb +46 -0
  34. data/lib/tzinfo/format2/timezone_definer.rb +94 -0
  35. data/lib/tzinfo/format2/timezone_definition.rb +73 -0
  36. data/lib/tzinfo/format2/timezone_index_definer.rb +45 -0
  37. data/lib/tzinfo/format2/timezone_index_definition.rb +55 -0
  38. data/lib/tzinfo/info_timezone.rb +26 -21
  39. data/lib/tzinfo/linked_timezone.rb +33 -52
  40. data/lib/tzinfo/offset_timezone_period.rb +42 -0
  41. data/lib/tzinfo/string_deduper.rb +118 -0
  42. data/lib/tzinfo/time_with_offset.rb +128 -0
  43. data/lib/tzinfo/timestamp.rb +548 -0
  44. data/lib/tzinfo/timestamp_with_offset.rb +85 -0
  45. data/lib/tzinfo/timezone.rb +989 -502
  46. data/lib/tzinfo/timezone_offset.rb +84 -74
  47. data/lib/tzinfo/timezone_period.rb +151 -217
  48. data/lib/tzinfo/timezone_proxy.rb +70 -79
  49. data/lib/tzinfo/timezone_transition.rb +77 -109
  50. data/lib/tzinfo/transitions_timezone_period.rb +63 -0
  51. data/lib/tzinfo/untaint_ext.rb +18 -0
  52. data/lib/tzinfo/version.rb +7 -0
  53. data/lib/tzinfo/with_offset.rb +61 -0
  54. metadata +43 -99
  55. metadata.gz.sig +0 -0
  56. data/Rakefile +0 -107
  57. data/lib/tzinfo/country_index_definition.rb +0 -31
  58. data/lib/tzinfo/country_info.rb +0 -42
  59. data/lib/tzinfo/data_timezone_info.rb +0 -55
  60. data/lib/tzinfo/linked_timezone_info.rb +0 -26
  61. data/lib/tzinfo/offset_rationals.rb +0 -77
  62. data/lib/tzinfo/ruby_core_support.rb +0 -176
  63. data/lib/tzinfo/ruby_country_info.rb +0 -74
  64. data/lib/tzinfo/ruby_data_source.rb +0 -138
  65. data/lib/tzinfo/time_or_datetime.rb +0 -340
  66. data/lib/tzinfo/timezone_definition.rb +0 -36
  67. data/lib/tzinfo/timezone_index_definition.rb +0 -54
  68. data/lib/tzinfo/timezone_info.rb +0 -30
  69. data/lib/tzinfo/timezone_transition_definition.rb +0 -104
  70. data/lib/tzinfo/transition_data_timezone_info.rb +0 -274
  71. data/lib/tzinfo/zoneinfo_country_info.rb +0 -37
  72. data/lib/tzinfo/zoneinfo_data_source.rb +0 -496
  73. data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -298
  74. data/test/tc_country.rb +0 -236
  75. data/test/tc_country_index_definition.rb +0 -69
  76. data/test/tc_country_info.rb +0 -16
  77. data/test/tc_country_timezone.rb +0 -173
  78. data/test/tc_data_source.rb +0 -218
  79. data/test/tc_data_timezone.rb +0 -99
  80. data/test/tc_data_timezone_info.rb +0 -18
  81. data/test/tc_info_timezone.rb +0 -34
  82. data/test/tc_linked_timezone.rb +0 -155
  83. data/test/tc_linked_timezone_info.rb +0 -23
  84. data/test/tc_offset_rationals.rb +0 -23
  85. data/test/tc_ruby_core_support.rb +0 -168
  86. data/test/tc_ruby_country_info.rb +0 -110
  87. data/test/tc_ruby_data_source.rb +0 -165
  88. data/test/tc_time_or_datetime.rb +0 -660
  89. data/test/tc_timezone.rb +0 -1359
  90. data/test/tc_timezone_definition.rb +0 -113
  91. data/test/tc_timezone_index_definition.rb +0 -73
  92. data/test/tc_timezone_info.rb +0 -11
  93. data/test/tc_timezone_london.rb +0 -143
  94. data/test/tc_timezone_melbourne.rb +0 -142
  95. data/test/tc_timezone_new_york.rb +0 -142
  96. data/test/tc_timezone_offset.rb +0 -126
  97. data/test/tc_timezone_period.rb +0 -555
  98. data/test/tc_timezone_proxy.rb +0 -136
  99. data/test/tc_timezone_transition.rb +0 -366
  100. data/test/tc_timezone_transition_definition.rb +0 -295
  101. data/test/tc_timezone_utc.rb +0 -27
  102. data/test/tc_transition_data_timezone_info.rb +0 -433
  103. data/test/tc_zoneinfo_country_info.rb +0 -78
  104. data/test/tc_zoneinfo_data_source.rb +0 -1204
  105. data/test/tc_zoneinfo_timezone_info.rb +0 -1234
  106. data/test/test_utils.rb +0 -188
  107. data/test/ts_all.rb +0 -7
  108. data/test/ts_all_ruby.rb +0 -5
  109. data/test/ts_all_zoneinfo.rb +0 -9
  110. data/test/tzinfo-data/tzinfo/data.rb +0 -8
  111. data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +0 -89
  112. data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +0 -315
  113. data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +0 -218
  114. data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +0 -19
  115. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +0 -21
  116. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +0 -21
  117. data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +0 -21
  118. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +0 -261
  119. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +0 -186
  120. data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +0 -321
  121. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +0 -265
  122. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +0 -220
  123. data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +0 -16
  124. data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +0 -927
  125. data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +0 -596
  126. data/test/tzinfo-data/tzinfo/data/version.rb +0 -14
  127. data/test/zoneinfo/America/Argentina/Buenos_Aires +0 -0
  128. data/test/zoneinfo/America/New_York +0 -0
  129. data/test/zoneinfo/Australia/Melbourne +0 -0
  130. data/test/zoneinfo/EST +0 -0
  131. data/test/zoneinfo/Etc/UTC +0 -0
  132. data/test/zoneinfo/Europe/Amsterdam +0 -0
  133. data/test/zoneinfo/Europe/Andorra +0 -0
  134. data/test/zoneinfo/Europe/London +0 -0
  135. data/test/zoneinfo/Europe/Paris +0 -0
  136. data/test/zoneinfo/Europe/Prague +0 -0
  137. data/test/zoneinfo/Factory +0 -0
  138. data/test/zoneinfo/iso3166.tab +0 -275
  139. data/test/zoneinfo/leapseconds +0 -61
  140. data/test/zoneinfo/posix/Europe/London +0 -0
  141. data/test/zoneinfo/posixrules +0 -0
  142. data/test/zoneinfo/right/Europe/London +0 -0
  143. data/test/zoneinfo/zone.tab +0 -439
  144. data/test/zoneinfo/zone1970.tab +0 -369
  145. data/tzinfo.gemspec +0 -21
@@ -1,99 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
-
3
- include TZInfo
4
-
5
- class TCDataTimezone < Minitest::Test
6
-
7
- class TestTimezoneInfo < TimezoneInfo
8
- attr_reader :utc
9
- attr_reader :local
10
- attr_reader :utc_to
11
- attr_reader :utc_from
12
-
13
- def initialize(identifier, utc_period, local_periods, transitions_up_to)
14
- super(identifier)
15
- @utc_period = utc_period
16
- @local_periods = local_periods || []
17
- @transitions_up_to = transitions_up_to
18
- end
19
-
20
- def period_for_utc(utc)
21
- @utc = utc
22
- @utc_period
23
- end
24
-
25
- def periods_for_local(local)
26
- @local = local
27
- @local_periods
28
- end
29
-
30
- def transitions_up_to(utc_to, utc_from = nil)
31
- @utc_to = utc_to
32
- @utc_from = utc_from
33
- @transitions_up_to
34
- end
35
- end
36
-
37
- def test_identifier
38
- tz = DataTimezone.new(TestTimezoneInfo.new('Test/Zone', nil, [], []))
39
- assert_equal('Test/Zone', tz.identifier)
40
- end
41
-
42
- def test_period_for_utc
43
- # Don't need actual TimezonePeriods. DataTimezone isn't supposed to do
44
- # anything with them apart from return them.
45
- period = Object.new
46
- tti = TestTimezoneInfo.new('Test/Zone', period, [], [])
47
- tz = DataTimezone.new(tti)
48
-
49
- t = Time.utc(2006, 6, 27, 22, 50, 12)
50
- assert_same(period, tz.period_for_utc(t))
51
- assert_same(t, tti.utc)
52
- end
53
-
54
- def test_periods_for_local
55
- # Don't need actual TimezonePeriods. DataTimezone isn't supposed to do
56
- # anything with them apart from return them.
57
- periods = [Object.new, Object.new]
58
- tti = TestTimezoneInfo.new('Test/Zone', nil, periods, [])
59
- tz = DataTimezone.new(tti)
60
-
61
- t = Time.utc(2006, 6, 27, 22, 50, 12)
62
- assert_same(periods, tz.periods_for_local(t))
63
- assert_same(t, tti.local)
64
- end
65
-
66
- def test_periods_for_local_not_found
67
- periods = []
68
- tti = TestTimezoneInfo.new('Test/Zone', nil, periods, [])
69
- tz = DataTimezone.new(tti)
70
-
71
- t = Time.utc(2006, 6, 27, 22, 50, 12)
72
- assert_same(periods, tz.periods_for_local(t))
73
- assert_same(t, tti.local)
74
- end
75
-
76
- def test_transitions_up_to
77
- # Don't need actual TimezoneTransition instances. DataTimezone isn't
78
- # supposed to do anything with them apart from return them.
79
- transitions = [Object.new, Object.new]
80
- tti = TestTimezoneInfo.new('Test/Zone', nil, nil, transitions)
81
- tz = DataTimezone.new(tti)
82
-
83
- utc_to = Time.utc(2013, 1, 1, 0, 0, 0)
84
- utc_from = Time.utc(2012, 1, 1, 0, 0, 0)
85
- assert_same(transitions, tz.transitions_up_to(utc_to, utc_from))
86
- assert_same(utc_to, tti.utc_to)
87
- assert_same(utc_from, tti.utc_from)
88
- end
89
-
90
- def test_canonical_identifier
91
- tz = DataTimezone.new(TestTimezoneInfo.new('Test/Zone', nil, [], []))
92
- assert_equal('Test/Zone', tz.canonical_identifier)
93
- end
94
-
95
- def test_canonical_zone
96
- tz = DataTimezone.new(TestTimezoneInfo.new('Test/Zone', nil, [], []))
97
- assert_same(tz, tz.canonical_zone)
98
- end
99
- end
@@ -1,18 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
-
3
- include TZInfo
4
-
5
- class TCDataTimezoneInfo < Minitest::Test
6
-
7
- def test_identifier
8
- ti = DataTimezoneInfo.new('Test/Zone')
9
- assert_equal('Test/Zone', ti.identifier)
10
- end
11
-
12
- def test_construct_timezone
13
- ti = DataTimezoneInfo.new('Test/Zone')
14
- tz = ti.create_timezone
15
- assert_kind_of(DataTimezone, tz)
16
- assert_equal('Test/Zone', tz.identifier)
17
- end
18
- end
@@ -1,34 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
-
3
- include TZInfo
4
-
5
- class TCInfoTimezone < Minitest::Test
6
-
7
- class TestInfoTimezone < InfoTimezone
8
- attr_reader :setup_info
9
-
10
- protected
11
- def setup(info)
12
- super(info)
13
- @setup_info = info
14
- end
15
- end
16
-
17
- def test_identifier
18
- tz = InfoTimezone.new(TimezoneInfo.new('Test/Identifier'))
19
- assert_equal('Test/Identifier', tz.identifier)
20
- end
21
-
22
- def test_info
23
- i = TimezoneInfo.new('Test/Identifier')
24
- tz = InfoTimezone.new(i)
25
- assert_same(i, tz.send(:info))
26
- end
27
-
28
- def test_setup
29
- i = TimezoneInfo.new('Test/Identifier')
30
- tz = TestInfoTimezone.new(i)
31
- assert_same(i, tz.setup_info)
32
- end
33
- end
34
-
@@ -1,155 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
-
3
- include TZInfo
4
-
5
- class TCLinkedTimezone < Minitest::Test
6
-
7
- class TestTimezone < Timezone
8
- attr_reader :utc_period
9
- attr_reader :local_periods
10
- attr_reader :up_to_transitions
11
- attr_reader :utc
12
- attr_reader :local
13
- attr_reader :utc_to
14
- attr_reader :utc_from
15
-
16
- def self.new(identifier, no_local_periods = false)
17
- tz = super()
18
- tz.send(:setup, identifier, no_local_periods)
19
- tz
20
- end
21
-
22
- def identifier
23
- @identifier
24
- end
25
-
26
- def period_for_utc(utc)
27
- @utc = utc
28
- @utc_period
29
- end
30
-
31
- def periods_for_local(local)
32
- @local = local
33
- raise PeriodNotFound if @no_local_periods
34
- @local_periods
35
- end
36
-
37
- def transitions_up_to(utc_to, utc_from = nil)
38
- @utc_to = utc_to
39
- @utc_from = utc_from
40
- @up_to_transitions
41
- end
42
-
43
- def canonical_zone
44
- self
45
- end
46
-
47
- private
48
- def setup(identifier, no_local_periods)
49
- @identifier = identifier
50
- @no_local_periods = no_local_periods
51
-
52
- # Don't have to be real TimezonePeriod or TimezoneTransition objects
53
- # (nothing will use them).
54
- @utc_period = Object.new
55
- @local_periods = [Object.new, Object.new]
56
- @up_to_transitions = [Object.new, Object.new]
57
- end
58
- end
59
-
60
-
61
- def setup
62
- # Redefine Timezone.get to return a fake timezone.
63
- # Use without_warnings to suppress redefined get method warning.
64
- without_warnings do
65
- def Timezone.get(identifier)
66
- raise InvalidTimezoneIdentifier, 'Invalid identifier' if identifier == 'Invalid/Identifier'
67
-
68
- @timezones ||= {}
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')
73
- end
74
- end
75
- end
76
-
77
- def teardown
78
- # Re-require timezone to reset.
79
- # Suppress redefined method warnings.
80
- without_warnings do
81
- load 'tzinfo/timezone.rb'
82
- end
83
- end
84
-
85
- def test_identifier
86
- tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked'))
87
- assert_equal('Test/Zone', tz.identifier)
88
- end
89
-
90
- def test_invalid_linked_identifier
91
- assert_raises(InvalidTimezoneIdentifier) { LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Invalid/Identifier')) }
92
- end
93
-
94
- def test_period_for_utc
95
- tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked'))
96
- linked_tz = Timezone.get('Test/Linked')
97
- t = Time.utc(2006, 6, 27, 23, 12, 28)
98
- assert_same(linked_tz.utc_period, tz.period_for_utc(t))
99
- assert_same(t, linked_tz.utc)
100
- end
101
-
102
- def test_periods_for_local
103
- tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked'))
104
- linked_tz = Timezone.get('Test/Linked')
105
- t = Time.utc(2006, 6, 27, 23, 12, 28)
106
- assert_same(linked_tz.local_periods, tz.periods_for_local(t))
107
- assert_same(t, linked_tz.local)
108
- end
109
-
110
- def test_periods_for_local_not_found
111
- tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/No/Local'))
112
- linked_tz = Timezone.get('Test/No/Local')
113
- t = Time.utc(2006, 6, 27, 23, 12, 28)
114
- assert_raises(PeriodNotFound) { tz.periods_for_local(t) }
115
- assert_same(t, linked_tz.local)
116
- end
117
-
118
- def test_transitions_up_to
119
- tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked'))
120
- linked_tz = Timezone.get('Test/Linked')
121
- utc_to = Time.utc(2013, 1, 1, 0, 0, 0)
122
- utc_from = Time.utc(2012, 1, 1, 0, 0, 0)
123
- assert_same(linked_tz.up_to_transitions, tz.transitions_up_to(utc_to, utc_from))
124
- assert_same(utc_to, linked_tz.utc_to)
125
- assert_same(utc_from, linked_tz.utc_from)
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
155
- end
@@ -1,23 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
-
3
- include TZInfo
4
-
5
- class TCLinkedTimezoneInfo < Minitest::Test
6
-
7
- def test_identifier
8
- lti = LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked')
9
- assert_equal('Test/Zone', lti.identifier)
10
- end
11
-
12
- def test_link_to_identifier
13
- lti = LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked')
14
- assert_equal('Test/Linked', lti.link_to_identifier)
15
- end
16
-
17
- def test_construct_timezone
18
- lti = LinkedTimezoneInfo.new('Test/Zone', 'Europe/London')
19
- tz = lti.create_timezone
20
- assert_kind_of(LinkedTimezone, tz)
21
- assert_equal('Test/Zone', tz.identifier)
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
-
3
- include TZInfo
4
-
5
- class TCOffsetRationals < Minitest::Test
6
- def test_rational_for_offset
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|
8
- assert_equal(Rational(seconds, 86400), OffsetRationals.rational_for_offset(seconds))
9
- }
10
- end
11
-
12
- def test_rational_for_offset_constant
13
- -28.upto(28) {|i|
14
- seconds = i * 30 * 60
15
-
16
- r1 = OffsetRationals.rational_for_offset(seconds)
17
- r2 = OffsetRationals.rational_for_offset(seconds)
18
-
19
- assert_equal(Rational(seconds, 86400), r1)
20
- assert_same(r1, r2)
21
- }
22
- end
23
- end
@@ -1,168 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
4
-
5
- include TZInfo
6
-
7
- class TCRubyCoreSupport < Minitest::Test
8
- def test_rational_new!
9
- assert_equal(Rational(3,4), RubyCoreSupport.rational_new!(3,4))
10
- end
11
-
12
- def test_datetime_new!
13
- assert_equal(DateTime.new(2008,10,5,12,0,0, 0, Date::ITALY), RubyCoreSupport.datetime_new!(2454745,0,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))
15
-
16
- assert_equal(DateTime.new(2008,10,5,20,30,0, 0, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(117827777, 48), 0, 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))
18
-
19
- assert_equal(DateTime.new(2008,10,6,6,26,21, 0, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(70696678127,28800), 0, 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))
21
-
22
- assert_equal(DateTime.new(-4712,1,1,12,0,0, 0, Date::ITALY), RubyCoreSupport.datetime_new!(0, 0, 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))
24
-
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))
27
-
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))
30
- end
31
-
32
- def test_datetime_new
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))
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))
35
-
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))
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))
38
- end
39
-
40
- def test_time_supports_negative
41
- if RubyCoreSupport.time_supports_negative
42
- assert_equal(Time.utc(1969, 12, 31, 23, 59, 59), Time.at(-1).utc)
43
- else
44
- assert_raises(ArgumentError) do
45
- Time.at(-1)
46
- end
47
- end
48
- end
49
-
50
- def test_time_supports_64_bit
51
- if RubyCoreSupport.time_supports_64bit
52
- assert_equal(Time.utc(1901, 12, 13, 20, 45, 51), Time.at(-2147483649).utc)
53
- assert_equal(Time.utc(2038, 1, 19, 3, 14, 8), Time.at(2147483648).utc)
54
- else
55
- assert_raises(RangeError) do
56
- Time.at(-2147483649)
57
- end
58
-
59
- assert_raises(RangeError) do
60
- Time.at(2147483648)
61
- end
62
- end
63
- end
64
-
65
- def test_time_nsec
66
- t = Time.utc(2013, 2, 6, 21, 56, 23, 567890 + Rational(123,1000))
67
-
68
- if t.respond_to?(:nsec)
69
- assert_equal(567890123, RubyCoreSupport.time_nsec(t))
70
- else
71
- assert_equal(567890000, RubyCoreSupport.time_nsec(t))
72
- end
73
- end
74
-
75
- def test_force_encoding
76
- s = [0xC2, 0xA9].pack('c2')
77
-
78
- if s.respond_to?(:force_encoding)
79
- # Ruby 1.9+ - should call String#force_encoding
80
- assert_equal('ASCII-8BIT', s.encoding.name)
81
- assert_equal(2, s.bytesize)
82
- result = RubyCoreSupport.force_encoding(s, 'UTF-8')
83
- assert_same(s, result)
84
- assert_equal('UTF-8', s.encoding.name)
85
- assert_equal(2, s.bytesize)
86
- assert_equal(1, s.length)
87
- assert_equal('©', s)
88
- else
89
- # Ruby 1.8 - no-op
90
- result = RubyCoreSupport.force_encoding(s, 'UTF-8')
91
- assert_same(s, result)
92
- assert_equal('©', s)
93
- end
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
168
- end