tzinfo 1.2.11 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.yardopts +3 -0
  4. data/CHANGES.md +469 -431
  5. data/LICENSE +13 -13
  6. data/README.md +368 -114
  7. data/lib/tzinfo/country.rb +131 -129
  8. data/lib/tzinfo/country_timezone.rb +70 -112
  9. data/lib/tzinfo/data_source.rb +389 -144
  10. data/lib/tzinfo/data_sources/constant_offset_data_timezone_info.rb +56 -0
  11. data/lib/tzinfo/data_sources/country_info.rb +42 -0
  12. data/lib/tzinfo/data_sources/data_timezone_info.rb +91 -0
  13. data/lib/tzinfo/data_sources/linked_timezone_info.rb +33 -0
  14. data/lib/tzinfo/data_sources/ruby_data_source.rb +141 -0
  15. data/lib/tzinfo/data_sources/timezone_info.rb +47 -0
  16. data/lib/tzinfo/data_sources/transitions_data_timezone_info.rb +214 -0
  17. data/lib/tzinfo/data_sources/zoneinfo_data_source.rb +573 -0
  18. data/lib/tzinfo/data_sources/zoneinfo_reader.rb +284 -0
  19. data/lib/tzinfo/data_sources.rb +8 -0
  20. data/lib/tzinfo/data_timezone.rb +33 -47
  21. data/lib/tzinfo/datetime_with_offset.rb +153 -0
  22. data/lib/tzinfo/format1/country_definer.rb +17 -0
  23. data/lib/tzinfo/format1/country_index_definition.rb +64 -0
  24. data/lib/tzinfo/format1/timezone_definer.rb +64 -0
  25. data/lib/tzinfo/format1/timezone_definition.rb +39 -0
  26. data/lib/tzinfo/format1/timezone_index_definition.rb +77 -0
  27. data/lib/tzinfo/format1.rb +10 -0
  28. data/lib/tzinfo/format2/country_definer.rb +68 -0
  29. data/lib/tzinfo/format2/country_index_definer.rb +68 -0
  30. data/lib/tzinfo/format2/country_index_definition.rb +46 -0
  31. data/lib/tzinfo/format2/timezone_definer.rb +94 -0
  32. data/lib/tzinfo/format2/timezone_definition.rb +73 -0
  33. data/lib/tzinfo/format2/timezone_index_definer.rb +45 -0
  34. data/lib/tzinfo/format2/timezone_index_definition.rb +55 -0
  35. data/lib/tzinfo/format2.rb +10 -0
  36. data/lib/tzinfo/info_timezone.rb +26 -21
  37. data/lib/tzinfo/linked_timezone.rb +33 -52
  38. data/lib/tzinfo/offset_timezone_period.rb +42 -0
  39. data/lib/tzinfo/string_deduper.rb +118 -0
  40. data/lib/tzinfo/time_with_offset.rb +128 -0
  41. data/lib/tzinfo/timestamp.rb +548 -0
  42. data/lib/tzinfo/timestamp_with_offset.rb +85 -0
  43. data/lib/tzinfo/timezone.rb +979 -502
  44. data/lib/tzinfo/timezone_offset.rb +84 -74
  45. data/lib/tzinfo/timezone_period.rb +151 -217
  46. data/lib/tzinfo/timezone_proxy.rb +70 -79
  47. data/lib/tzinfo/timezone_transition.rb +77 -109
  48. data/lib/tzinfo/transitions_timezone_period.rb +63 -0
  49. data/lib/tzinfo/version.rb +7 -0
  50. data/lib/tzinfo/with_offset.rb +61 -0
  51. data/lib/tzinfo.rb +60 -40
  52. data.tar.gz.sig +0 -0
  53. metadata +51 -115
  54. metadata.gz.sig +2 -3
  55. data/Rakefile +0 -107
  56. data/lib/tzinfo/annual_rules.rb +0 -51
  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/posix_time_zone_parser.rb +0 -136
  63. data/lib/tzinfo/ruby_core_support.rb +0 -176
  64. data/lib/tzinfo/ruby_country_info.rb +0 -74
  65. data/lib/tzinfo/ruby_data_source.rb +0 -136
  66. data/lib/tzinfo/time_or_datetime.rb +0 -351
  67. data/lib/tzinfo/timezone_definition.rb +0 -36
  68. data/lib/tzinfo/timezone_index_definition.rb +0 -54
  69. data/lib/tzinfo/timezone_info.rb +0 -30
  70. data/lib/tzinfo/timezone_transition_definition.rb +0 -104
  71. data/lib/tzinfo/transition_data_timezone_info.rb +0 -274
  72. data/lib/tzinfo/transition_rule.rb +0 -325
  73. data/lib/tzinfo/zoneinfo_country_info.rb +0 -37
  74. data/lib/tzinfo/zoneinfo_data_source.rb +0 -504
  75. data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -516
  76. data/test/assets/payload.rb +0 -1
  77. data/test/tc_annual_rules.rb +0 -95
  78. data/test/tc_country.rb +0 -240
  79. data/test/tc_country_index_definition.rb +0 -69
  80. data/test/tc_country_info.rb +0 -16
  81. data/test/tc_country_timezone.rb +0 -173
  82. data/test/tc_data_source.rb +0 -218
  83. data/test/tc_data_timezone.rb +0 -99
  84. data/test/tc_data_timezone_info.rb +0 -18
  85. data/test/tc_info_timezone.rb +0 -34
  86. data/test/tc_linked_timezone.rb +0 -155
  87. data/test/tc_linked_timezone_info.rb +0 -23
  88. data/test/tc_offset_rationals.rb +0 -23
  89. data/test/tc_posix_time_zone_parser.rb +0 -261
  90. data/test/tc_ruby_core_support.rb +0 -168
  91. data/test/tc_ruby_country_info.rb +0 -110
  92. data/test/tc_ruby_data_source.rb +0 -175
  93. data/test/tc_time_or_datetime.rb +0 -674
  94. data/test/tc_timezone.rb +0 -1361
  95. data/test/tc_timezone_definition.rb +0 -113
  96. data/test/tc_timezone_index_definition.rb +0 -73
  97. data/test/tc_timezone_info.rb +0 -11
  98. data/test/tc_timezone_london.rb +0 -143
  99. data/test/tc_timezone_melbourne.rb +0 -142
  100. data/test/tc_timezone_new_york.rb +0 -142
  101. data/test/tc_timezone_offset.rb +0 -126
  102. data/test/tc_timezone_period.rb +0 -555
  103. data/test/tc_timezone_proxy.rb +0 -136
  104. data/test/tc_timezone_transition.rb +0 -366
  105. data/test/tc_timezone_transition_definition.rb +0 -295
  106. data/test/tc_timezone_utc.rb +0 -27
  107. data/test/tc_transition_data_timezone_info.rb +0 -433
  108. data/test/tc_transition_rule.rb +0 -663
  109. data/test/tc_zoneinfo_country_info.rb +0 -78
  110. data/test/tc_zoneinfo_data_source.rb +0 -1226
  111. data/test/tc_zoneinfo_timezone_info.rb +0 -2149
  112. data/test/test_utils.rb +0 -214
  113. data/test/ts_all.rb +0 -7
  114. data/test/ts_all_ruby.rb +0 -5
  115. data/test/ts_all_zoneinfo.rb +0 -9
  116. data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +0 -89
  117. data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +0 -327
  118. data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +0 -230
  119. data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +0 -19
  120. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +0 -21
  121. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +0 -21
  122. data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +0 -21
  123. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +0 -273
  124. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +0 -198
  125. data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +0 -333
  126. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +0 -277
  127. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +0 -235
  128. data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +0 -16
  129. data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +0 -940
  130. data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +0 -609
  131. data/test/tzinfo-data/tzinfo/data/version.rb +0 -20
  132. data/test/tzinfo-data/tzinfo/data.rb +0 -8
  133. data/test/zoneinfo/America/Argentina/Buenos_Aires +0 -0
  134. data/test/zoneinfo/America/New_York +0 -0
  135. data/test/zoneinfo/Australia/Melbourne +0 -0
  136. data/test/zoneinfo/EST +0 -0
  137. data/test/zoneinfo/Etc/UTC +0 -0
  138. data/test/zoneinfo/Europe/Amsterdam +0 -0
  139. data/test/zoneinfo/Europe/Andorra +0 -0
  140. data/test/zoneinfo/Europe/London +0 -0
  141. data/test/zoneinfo/Europe/Paris +0 -0
  142. data/test/zoneinfo/Europe/Prague +0 -0
  143. data/test/zoneinfo/Factory +0 -0
  144. data/test/zoneinfo/iso3166.tab +0 -274
  145. data/test/zoneinfo/leapseconds +0 -78
  146. data/test/zoneinfo/posix/Europe/London +0 -0
  147. data/test/zoneinfo/posixrules +0 -0
  148. data/test/zoneinfo/right/Europe/London +0 -0
  149. data/test/zoneinfo/zone.tab +0 -452
  150. data/test/zoneinfo/zone1970.tab +0 -384
  151. data/tzinfo.gemspec +0 -21
@@ -1,351 +0,0 @@
1
- require 'date'
2
- require 'rational' unless defined?(Rational)
3
- require 'time'
4
-
5
- module TZInfo
6
- # Used by TZInfo internally to represent either a Time, DateTime or
7
- # an Integer timestamp (seconds since 1970-01-01 00:00:00).
8
- class TimeOrDateTime
9
- include Comparable
10
-
11
- # Constructs a new TimeOrDateTime. timeOrDateTime can be a Time, DateTime
12
- # or Integer. If using a Time or DateTime, any time zone information
13
- # is ignored.
14
- #
15
- # Integer timestamps must be within the range supported by Time on the
16
- # platform being used.
17
- def initialize(timeOrDateTime)
18
- @time = nil
19
- @datetime = nil
20
- @timestamp = nil
21
-
22
- if timeOrDateTime.is_a?(Time)
23
- @time = timeOrDateTime
24
-
25
- # Avoid using the slower Rational class unless necessary.
26
- nsec = RubyCoreSupport.time_nsec(@time)
27
- usec = nsec % 1000 == 0 ? nsec / 1000 : Rational(nsec, 1000)
28
-
29
- @time = Time.utc(@time.year, @time.mon, @time.mday, @time.hour, @time.min, @time.sec, usec) unless @time.utc?
30
- @orig = @time
31
- elsif timeOrDateTime.is_a?(DateTime)
32
- @datetime = timeOrDateTime
33
- @datetime = @datetime.new_offset(0) unless @datetime.offset == 0
34
- @orig = @datetime
35
- else
36
- @timestamp = timeOrDateTime.to_i
37
-
38
- if !RubyCoreSupport.time_supports_64bit && (@timestamp > 2147483647 || @timestamp < -2147483648 || (@timestamp < 0 && !RubyCoreSupport.time_supports_negative))
39
- raise RangeError, 'Timestamp is outside the supported range of Time on this platform'
40
- end
41
-
42
- @orig = @timestamp
43
- end
44
- end
45
-
46
- # Returns the time as a Time.
47
- #
48
- # When converting from a DateTime, the result is truncated to microsecond
49
- # precision.
50
- def to_time
51
- # Thread-safety: It is possible that the value of @time may be
52
- # calculated multiple times in concurrently executing threads. It is not
53
- # worth the overhead of locking to ensure that @time is only
54
- # calculated once.
55
-
56
- unless @time
57
- result = if @timestamp
58
- Time.at(@timestamp).utc
59
- else
60
- Time.utc(year, mon, mday, hour, min, sec, usec)
61
- end
62
-
63
- return result if frozen?
64
- @time = result
65
- end
66
-
67
- @time
68
- end
69
-
70
- # Returns the time as a DateTime.
71
- #
72
- # When converting from a Time, the result is truncated to microsecond
73
- # precision.
74
- def to_datetime
75
- # Thread-safety: It is possible that the value of @datetime may be
76
- # calculated multiple times in concurrently executing threads. It is not
77
- # worth the overhead of locking to ensure that @datetime is only
78
- # calculated once.
79
-
80
- unless @datetime
81
- # Avoid using Rational unless necessary.
82
- u = usec
83
- s = u == 0 ? sec : Rational(sec * 1000000 + u, 1000000)
84
- result = RubyCoreSupport.datetime_new(year, mon, mday, hour, min, s)
85
- return result if frozen?
86
- @datetime = result
87
- end
88
-
89
- @datetime
90
- end
91
-
92
- # Returns the time as an integer timestamp.
93
- def to_i
94
- # Thread-safety: It is possible that the value of @timestamp may be
95
- # calculated multiple times in concurrently executing threads. It is not
96
- # worth the overhead of locking to ensure that @timestamp is only
97
- # calculated once.
98
-
99
- unless @timestamp
100
- result = to_time.to_i
101
- return result if frozen?
102
- @timestamp = result
103
- end
104
-
105
- @timestamp
106
- end
107
-
108
- # Returns the time as the original time passed to new.
109
- def to_orig
110
- @orig
111
- end
112
-
113
- # Returns a string representation of the TimeOrDateTime.
114
- def to_s
115
- if @orig.is_a?(Time)
116
- "Time: #{@orig.to_s}"
117
- elsif @orig.is_a?(DateTime)
118
- "DateTime: #{@orig.to_s}"
119
- else
120
- "Timestamp: #{@orig.to_s}"
121
- end
122
- end
123
-
124
- # Returns internal object state as a programmer-readable string.
125
- def inspect
126
- "#<#{self.class}: #{@orig.inspect}>"
127
- end
128
-
129
- # Returns the year.
130
- def year
131
- if @time
132
- @time.year
133
- elsif @datetime
134
- @datetime.year
135
- else
136
- to_time.year
137
- end
138
- end
139
-
140
- # Returns the month of the year (1..12).
141
- def mon
142
- if @time
143
- @time.mon
144
- elsif @datetime
145
- @datetime.mon
146
- else
147
- to_time.mon
148
- end
149
- end
150
- alias :month :mon
151
-
152
- # Returns the day of the month (1..n).
153
- def mday
154
- if @time
155
- @time.mday
156
- elsif @datetime
157
- @datetime.mday
158
- else
159
- to_time.mday
160
- end
161
- end
162
- alias :day :mday
163
-
164
- # Returns the day of the week (0..6 for Sunday to Saturday).
165
- def wday
166
- if @time
167
- @time.wday
168
- elsif @datetime
169
- @datetime.wday
170
- else
171
- to_time.wday
172
- end
173
- end
174
-
175
- # Returns the hour of the day (0..23).
176
- def hour
177
- if @time
178
- @time.hour
179
- elsif @datetime
180
- @datetime.hour
181
- else
182
- to_time.hour
183
- end
184
- end
185
-
186
- # Returns the minute of the hour (0..59).
187
- def min
188
- if @time
189
- @time.min
190
- elsif @datetime
191
- @datetime.min
192
- else
193
- to_time.min
194
- end
195
- end
196
-
197
- # Returns the second of the minute (0..60). (60 for a leap second).
198
- def sec
199
- if @time
200
- @time.sec
201
- elsif @datetime
202
- @datetime.sec
203
- else
204
- to_time.sec
205
- end
206
- end
207
-
208
- # Returns the number of microseconds for the time.
209
- def usec
210
- if @time
211
- @time.usec
212
- elsif @datetime
213
- # Ruby 1.8 has sec_fraction (of which the documentation says
214
- # 'I do NOT recommend you to use this method'). sec_fraction no longer
215
- # exists in Ruby 1.9.
216
-
217
- # Calculate the sec_fraction from the day_fraction.
218
- ((@datetime.day_fraction - OffsetRationals.rational_for_offset(@datetime.hour * 3600 + @datetime.min * 60 + @datetime.sec)) * 86400000000).to_i
219
- else
220
- 0
221
- end
222
- end
223
-
224
- # Compares this TimeOrDateTime with another Time, DateTime, timestamp
225
- # (Integer) or TimeOrDateTime. Returns -1, 0 or +1 depending
226
- # whether the receiver is less than, equal to, or greater than
227
- # timeOrDateTime.
228
- #
229
- # Returns nil if the passed in timeOrDateTime is not comparable with
230
- # TimeOrDateTime instances.
231
- #
232
- # Comparisons involving a DateTime will be performed using DateTime#<=>.
233
- # Comparisons that don't involve a DateTime, but include a Time will be
234
- # performed with Time#<=>. Otherwise comparisons will be performed with
235
- # Integer#<=>.
236
- def <=>(timeOrDateTime)
237
- return nil unless timeOrDateTime.is_a?(TimeOrDateTime) ||
238
- timeOrDateTime.is_a?(Time) ||
239
- timeOrDateTime.is_a?(DateTime) ||
240
- timeOrDateTime.respond_to?(:to_i)
241
-
242
- unless timeOrDateTime.is_a?(TimeOrDateTime)
243
- timeOrDateTime = TimeOrDateTime.wrap(timeOrDateTime)
244
- end
245
-
246
- orig = timeOrDateTime.to_orig
247
-
248
- if @orig.is_a?(DateTime) || orig.is_a?(DateTime)
249
- # If either is a DateTime, assume it is there for a reason
250
- # (i.e. for its larger range of acceptable values on 32-bit systems).
251
- to_datetime <=> timeOrDateTime.to_datetime
252
- elsif @orig.is_a?(Time) || orig.is_a?(Time)
253
- to_time <=> timeOrDateTime.to_time
254
- else
255
- to_i <=> timeOrDateTime.to_i
256
- end
257
- end
258
-
259
- # Adds a number of seconds to the TimeOrDateTime. Returns a new
260
- # TimeOrDateTime, preserving what the original constructed type was.
261
- # If the original type is a Time and the resulting calculation goes out of
262
- # range for Times, then an exception will be raised by the Time class.
263
- def +(seconds)
264
- if seconds == 0
265
- self
266
- else
267
- if @orig.is_a?(DateTime)
268
- TimeOrDateTime.new(@orig + OffsetRationals.rational_for_offset(seconds))
269
- else
270
- # + defined for Time and Integer
271
- TimeOrDateTime.new(@orig + seconds)
272
- end
273
- end
274
- end
275
-
276
- # Subtracts a number of seconds from the TimeOrDateTime. Returns a new
277
- # TimeOrDateTime, preserving what the original constructed type was.
278
- # If the original type is a Time and the resulting calculation goes out of
279
- # range for Times, then an exception will be raised by the Time class.
280
- def -(seconds)
281
- self + (-seconds)
282
- end
283
-
284
- # Similar to the + operator, but converts to a DateTime based TimeOrDateTime
285
- # where the Time or Integer timestamp to go out of the allowed range for a
286
- # Time, converts to a DateTime based TimeOrDateTime.
287
- #
288
- # Note that the range of Time varies based on the platform.
289
- def add_with_convert(seconds)
290
- if seconds == 0
291
- self
292
- else
293
- if @orig.is_a?(DateTime)
294
- TimeOrDateTime.new(@orig + OffsetRationals.rational_for_offset(seconds))
295
- else
296
- # A Time or timestamp.
297
- result = to_i + seconds
298
-
299
- if ((result > 2147483647 || result < -2147483648) && !RubyCoreSupport.time_supports_64bit) || (result < 0 && !RubyCoreSupport.time_supports_negative)
300
- result = TimeOrDateTime.new(to_datetime + OffsetRationals.rational_for_offset(seconds))
301
- else
302
- result = TimeOrDateTime.new(@orig + seconds)
303
- end
304
- end
305
- end
306
- end
307
-
308
- # Returns true if todt represents the same time and was originally
309
- # constructed with the same type (DateTime, Time or timestamp) as this
310
- # TimeOrDateTime.
311
- def eql?(todt)
312
- todt.kind_of?(TimeOrDateTime) && to_orig.eql?(todt.to_orig)
313
- end
314
-
315
- # Returns a hash of this TimeOrDateTime.
316
- def hash
317
- @orig.hash
318
- end
319
-
320
- # If no block is given, returns a TimeOrDateTime wrapping the given
321
- # timeOrDateTime. If a block is specified, a TimeOrDateTime is constructed
322
- # and passed to the block. The result of the block must be a TimeOrDateTime.
323
- #
324
- # The result of the block will be converted to the type of the originally
325
- # passed in timeOrDateTime and then returned as the result of wrap.
326
- #
327
- # timeOrDateTime can be a Time, DateTime, timestamp (Integer) or
328
- # TimeOrDateTime. If a TimeOrDateTime is passed in, no new TimeOrDateTime
329
- # will be constructed and the value passed to wrap will be used when
330
- # calling the block.
331
- def self.wrap(timeOrDateTime)
332
- t = timeOrDateTime.is_a?(TimeOrDateTime) ? timeOrDateTime : TimeOrDateTime.new(timeOrDateTime)
333
-
334
- if block_given?
335
- t = yield t
336
-
337
- if timeOrDateTime.is_a?(TimeOrDateTime)
338
- t
339
- elsif timeOrDateTime.is_a?(Time)
340
- t.to_time
341
- elsif timeOrDateTime.is_a?(DateTime)
342
- t.to_datetime
343
- else
344
- t.to_i
345
- end
346
- else
347
- t
348
- end
349
- end
350
- end
351
- end
@@ -1,36 +0,0 @@
1
- module TZInfo
2
-
3
- # TimezoneDefinition is included into Timezone definition modules.
4
- # TimezoneDefinition provides the methods for defining timezones.
5
- #
6
- # @private
7
- module TimezoneDefinition #:nodoc:
8
- # Add class methods to the includee.
9
- def self.append_features(base)
10
- super
11
- base.extend(ClassMethods)
12
- end
13
-
14
- # Class methods for inclusion.
15
- #
16
- # @private
17
- module ClassMethods #:nodoc:
18
- # Returns and yields a TransitionDataTimezoneInfo object to define a
19
- # timezone.
20
- def timezone(identifier)
21
- yield @timezone = TransitionDataTimezoneInfo.new(identifier)
22
- end
23
-
24
- # Defines a linked timezone.
25
- def linked_timezone(identifier, link_to_identifier)
26
- @timezone = LinkedTimezoneInfo.new(identifier, link_to_identifier)
27
- end
28
-
29
- # Returns the last TimezoneInfo to be defined with timezone or
30
- # linked_timezone.
31
- def get
32
- @timezone
33
- end
34
- end
35
- end
36
- end
@@ -1,54 +0,0 @@
1
- module TZInfo
2
- # The timezone index file includes TimezoneIndexDefinition which provides
3
- # methods used to define timezones in the index.
4
- #
5
- # @private
6
- module TimezoneIndexDefinition #:nodoc:
7
- # Add class methods to the includee and initialize class instance variables.
8
- def self.append_features(base)
9
- super
10
- base.extend(ClassMethods)
11
- base.instance_eval do
12
- @timezones = []
13
- @data_timezones = []
14
- @linked_timezones = []
15
- end
16
- end
17
-
18
- # Class methods for inclusion.
19
- #
20
- # @private
21
- module ClassMethods #:nodoc:
22
- # Defines a timezone based on data.
23
- def timezone(identifier)
24
- @timezones << identifier
25
- @data_timezones << identifier
26
- end
27
-
28
- # Defines a timezone which is a link to another timezone.
29
- def linked_timezone(identifier)
30
- @timezones << identifier
31
- @linked_timezones << identifier
32
- end
33
-
34
- # Returns a frozen array containing the identifiers of all the timezones.
35
- # Identifiers appear in the order they were defined in the index.
36
- def timezones
37
- @timezones.freeze
38
- end
39
-
40
- # Returns a frozen array containing the identifiers of all data timezones.
41
- # Identifiers appear in the order they were defined in the index.
42
- def data_timezones
43
- @data_timezones.freeze
44
- end
45
-
46
- # Returns a frozen array containing the identifiers of all linked
47
- # timezones. Identifiers appear in the order they were defined in
48
- # the index.
49
- def linked_timezones
50
- @linked_timezones.freeze
51
- end
52
- end
53
- end
54
- end
@@ -1,30 +0,0 @@
1
- module TZInfo
2
- # Represents a timezone defined by a data source.
3
- class TimezoneInfo
4
-
5
- # The timezone identifier.
6
- attr_reader :identifier
7
-
8
- # Constructs a new TimezoneInfo with an identifier.
9
- def initialize(identifier)
10
- @identifier = identifier
11
- end
12
-
13
- # Returns internal object state as a programmer-readable string.
14
- def inspect
15
- "#<#{self.class}: #@identifier>"
16
- end
17
-
18
- # Constructs a Timezone instance for the timezone represented by this
19
- # TimezoneInfo.
20
- def create_timezone
21
- raise_not_implemented('create_timezone')
22
- end
23
-
24
- private
25
-
26
- def raise_not_implemented(method_name)
27
- raise NotImplementedError, "Subclasses must override #{method_name}"
28
- end
29
- end
30
- end
@@ -1,104 +0,0 @@
1
- module TZInfo
2
- # A TimezoneTransition defined by as integer timestamp, as a rational to
3
- # create a DateTime or as both.
4
- #
5
- # @private
6
- class TimezoneTransitionDefinition < TimezoneTransition #:nodoc:
7
- # The numerator of the DateTime if the transition time is defined as a
8
- # DateTime, otherwise the transition time as a timestamp.
9
- attr_reader :numerator_or_time
10
- protected :numerator_or_time
11
-
12
- # Either the denominator of the DateTime if the transition time is defined
13
- # as a DateTime, otherwise nil.
14
- attr_reader :denominator
15
- protected :denominator
16
-
17
- # Creates a new TimezoneTransitionDefinition with the given offset,
18
- # previous_offset (both TimezoneOffset instances) and UTC time.
19
- #
20
- # The time can be specified as a timestamp, as a rational to create a
21
- # DateTime, or as both.
22
- #
23
- # If both a timestamp and rational are given, then the rational will only
24
- # be used if the timestamp falls outside of the range of Time on the
25
- # platform being used at runtime.
26
- #
27
- # DateTimes are created from the rational as follows:
28
- #
29
- # RubyCoreSupport.datetime_new!(RubyCoreSupport.rational_new!(numerator, denominator), 0, Date::ITALY)
30
- #
31
- # For performance reasons, the numerator and denominator must be specified
32
- # in their lowest form.
33
- def initialize(offset, previous_offset, numerator_or_timestamp, denominator_or_numerator = nil, denominator = nil)
34
- super(offset, previous_offset)
35
-
36
- if denominator
37
- numerator = denominator_or_numerator
38
- timestamp = numerator_or_timestamp
39
- elsif denominator_or_numerator
40
- numerator = numerator_or_timestamp
41
- denominator = denominator_or_numerator
42
- timestamp = nil
43
- else
44
- numerator = nil
45
- denominator = nil
46
- timestamp = numerator_or_timestamp
47
- end
48
-
49
- # Determine whether to use the timestamp or the numerator and denominator.
50
- if numerator && (
51
- !timestamp ||
52
- (timestamp < 0 && !RubyCoreSupport.time_supports_negative) ||
53
- ((timestamp < -2147483648 || timestamp > 2147483647) && !RubyCoreSupport.time_supports_64bit)
54
- )
55
-
56
- @numerator_or_time = numerator
57
- @denominator = denominator
58
- else
59
- @numerator_or_time = timestamp
60
- @denominator = nil
61
- end
62
-
63
- @at = nil
64
- end
65
-
66
- # A TimeOrDateTime instance representing the UTC time when this transition
67
- # occurs.
68
- def at
69
- # Thread-safety: It is possible that the value of @at may be calculated
70
- # multiple times in concurrently executing threads. It is not worth the
71
- # overhead of locking to ensure that @at is only calculated once.
72
-
73
- unless @at
74
- result = unless @denominator
75
- TimeOrDateTime.new(@numerator_or_time)
76
- else
77
- r = RubyCoreSupport.rational_new!(@numerator_or_time, @denominator)
78
- dt = RubyCoreSupport.datetime_new!(r, 0, Date::ITALY)
79
- TimeOrDateTime.new(dt)
80
- end
81
-
82
- return result if frozen?
83
- @at = result
84
- end
85
-
86
- @at
87
- end
88
-
89
- # Returns true if this TimezoneTransitionDefinition is equal to the given
90
- # TimezoneTransitionDefinition. Two TimezoneTransitionDefinition instances
91
- # are considered to be equal by eql? if offset, previous_offset,
92
- # numerator_or_time and denominator are all equal.
93
- def eql?(tti)
94
- tti.kind_of?(TimezoneTransitionDefinition) &&
95
- offset == tti.offset && previous_offset == tti.previous_offset &&
96
- numerator_or_time == tti.numerator_or_time && denominator == tti.denominator
97
- end
98
-
99
- # Returns a hash of this TimezoneTransitionDefinition instance.
100
- def hash
101
- @offset.hash ^ @previous_offset.hash ^ @numerator_or_time.hash ^ @denominator.hash
102
- end
103
- end
104
- end