tzinfo 1.2.6 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -1
- data/.yardopts +3 -0
- data/CHANGES.md +494 -380
- data/LICENSE +13 -13
- data/README.md +368 -114
- data/lib/tzinfo.rb +59 -29
- data/lib/tzinfo/country.rb +141 -129
- data/lib/tzinfo/country_timezone.rb +70 -112
- data/lib/tzinfo/data_source.rb +389 -144
- data/lib/tzinfo/data_sources.rb +8 -0
- data/lib/tzinfo/data_sources/constant_offset_data_timezone_info.rb +56 -0
- data/lib/tzinfo/data_sources/country_info.rb +42 -0
- data/lib/tzinfo/data_sources/data_timezone_info.rb +91 -0
- data/lib/tzinfo/data_sources/linked_timezone_info.rb +33 -0
- data/lib/tzinfo/data_sources/ruby_data_source.rb +145 -0
- data/lib/tzinfo/data_sources/timezone_info.rb +47 -0
- data/lib/tzinfo/data_sources/transitions_data_timezone_info.rb +214 -0
- data/lib/tzinfo/data_sources/zoneinfo_data_source.rb +577 -0
- data/lib/tzinfo/data_sources/zoneinfo_reader.rb +288 -0
- data/lib/tzinfo/data_timezone.rb +33 -47
- data/lib/tzinfo/datetime_with_offset.rb +153 -0
- data/lib/tzinfo/format1.rb +10 -0
- data/lib/tzinfo/format1/country_definer.rb +17 -0
- data/lib/tzinfo/format1/country_index_definition.rb +64 -0
- data/lib/tzinfo/format1/timezone_definer.rb +64 -0
- data/lib/tzinfo/format1/timezone_definition.rb +39 -0
- data/lib/tzinfo/format1/timezone_index_definition.rb +77 -0
- data/lib/tzinfo/format2.rb +10 -0
- data/lib/tzinfo/format2/country_definer.rb +68 -0
- data/lib/tzinfo/format2/country_index_definer.rb +68 -0
- data/lib/tzinfo/format2/country_index_definition.rb +46 -0
- data/lib/tzinfo/format2/timezone_definer.rb +94 -0
- data/lib/tzinfo/format2/timezone_definition.rb +73 -0
- data/lib/tzinfo/format2/timezone_index_definer.rb +45 -0
- data/lib/tzinfo/format2/timezone_index_definition.rb +55 -0
- data/lib/tzinfo/info_timezone.rb +26 -21
- data/lib/tzinfo/linked_timezone.rb +33 -52
- data/lib/tzinfo/offset_timezone_period.rb +42 -0
- data/lib/tzinfo/string_deduper.rb +118 -0
- data/lib/tzinfo/time_with_offset.rb +128 -0
- data/lib/tzinfo/timestamp.rb +548 -0
- data/lib/tzinfo/timestamp_with_offset.rb +85 -0
- data/lib/tzinfo/timezone.rb +989 -502
- data/lib/tzinfo/timezone_offset.rb +84 -74
- data/lib/tzinfo/timezone_period.rb +151 -217
- data/lib/tzinfo/timezone_proxy.rb +70 -79
- data/lib/tzinfo/timezone_transition.rb +77 -109
- data/lib/tzinfo/transitions_timezone_period.rb +63 -0
- data/lib/tzinfo/untaint_ext.rb +18 -0
- data/lib/tzinfo/version.rb +7 -0
- data/lib/tzinfo/with_offset.rb +61 -0
- metadata +44 -100
- metadata.gz.sig +0 -0
- data/Rakefile +0 -107
- data/lib/tzinfo/country_index_definition.rb +0 -31
- data/lib/tzinfo/country_info.rb +0 -42
- data/lib/tzinfo/data_timezone_info.rb +0 -55
- data/lib/tzinfo/linked_timezone_info.rb +0 -26
- data/lib/tzinfo/offset_rationals.rb +0 -77
- data/lib/tzinfo/ruby_core_support.rb +0 -176
- data/lib/tzinfo/ruby_country_info.rb +0 -74
- data/lib/tzinfo/ruby_data_source.rb +0 -138
- data/lib/tzinfo/time_or_datetime.rb +0 -340
- data/lib/tzinfo/timezone_definition.rb +0 -36
- data/lib/tzinfo/timezone_index_definition.rb +0 -54
- data/lib/tzinfo/timezone_info.rb +0 -30
- data/lib/tzinfo/timezone_transition_definition.rb +0 -104
- data/lib/tzinfo/transition_data_timezone_info.rb +0 -274
- data/lib/tzinfo/zoneinfo_country_info.rb +0 -37
- data/lib/tzinfo/zoneinfo_data_source.rb +0 -496
- data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -298
- data/test/tc_country.rb +0 -236
- data/test/tc_country_index_definition.rb +0 -69
- data/test/tc_country_info.rb +0 -16
- data/test/tc_country_timezone.rb +0 -173
- data/test/tc_data_source.rb +0 -218
- data/test/tc_data_timezone.rb +0 -99
- data/test/tc_data_timezone_info.rb +0 -18
- data/test/tc_info_timezone.rb +0 -34
- data/test/tc_linked_timezone.rb +0 -155
- data/test/tc_linked_timezone_info.rb +0 -23
- data/test/tc_offset_rationals.rb +0 -23
- data/test/tc_ruby_core_support.rb +0 -168
- data/test/tc_ruby_country_info.rb +0 -110
- data/test/tc_ruby_data_source.rb +0 -165
- data/test/tc_time_or_datetime.rb +0 -660
- data/test/tc_timezone.rb +0 -1359
- data/test/tc_timezone_definition.rb +0 -113
- data/test/tc_timezone_index_definition.rb +0 -73
- data/test/tc_timezone_info.rb +0 -11
- data/test/tc_timezone_london.rb +0 -143
- data/test/tc_timezone_melbourne.rb +0 -142
- data/test/tc_timezone_new_york.rb +0 -142
- data/test/tc_timezone_offset.rb +0 -126
- data/test/tc_timezone_period.rb +0 -555
- data/test/tc_timezone_proxy.rb +0 -136
- data/test/tc_timezone_transition.rb +0 -366
- data/test/tc_timezone_transition_definition.rb +0 -295
- data/test/tc_timezone_utc.rb +0 -27
- data/test/tc_transition_data_timezone_info.rb +0 -433
- data/test/tc_zoneinfo_country_info.rb +0 -78
- data/test/tc_zoneinfo_data_source.rb +0 -1204
- data/test/tc_zoneinfo_timezone_info.rb +0 -1234
- data/test/test_utils.rb +0 -188
- data/test/ts_all.rb +0 -7
- data/test/ts_all_ruby.rb +0 -5
- data/test/ts_all_zoneinfo.rb +0 -9
- data/test/tzinfo-data/tzinfo/data.rb +0 -8
- data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +0 -89
- data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +0 -315
- data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +0 -218
- data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +0 -19
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +0 -21
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +0 -21
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +0 -21
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +0 -261
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +0 -186
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +0 -321
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +0 -265
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +0 -220
- data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +0 -16
- data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +0 -927
- data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +0 -596
- data/test/tzinfo-data/tzinfo/data/version.rb +0 -14
- data/test/zoneinfo/America/Argentina/Buenos_Aires +0 -0
- data/test/zoneinfo/America/New_York +0 -0
- data/test/zoneinfo/Australia/Melbourne +0 -0
- data/test/zoneinfo/EST +0 -0
- data/test/zoneinfo/Etc/UTC +0 -0
- data/test/zoneinfo/Europe/Amsterdam +0 -0
- data/test/zoneinfo/Europe/Andorra +0 -0
- data/test/zoneinfo/Europe/London +0 -0
- data/test/zoneinfo/Europe/Paris +0 -0
- data/test/zoneinfo/Europe/Prague +0 -0
- data/test/zoneinfo/Factory +0 -0
- data/test/zoneinfo/iso3166.tab +0 -275
- data/test/zoneinfo/leapseconds +0 -61
- data/test/zoneinfo/posix/Europe/London +0 -0
- data/test/zoneinfo/posixrules +0 -0
- data/test/zoneinfo/right/Europe/London +0 -0
- data/test/zoneinfo/zone.tab +0 -439
- data/test/zoneinfo/zone1970.tab +0 -369
- data/tzinfo.gemspec +0 -21
@@ -1,340 +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 hour of the day (0..23).
|
165
|
-
def hour
|
166
|
-
if @time
|
167
|
-
@time.hour
|
168
|
-
elsif @datetime
|
169
|
-
@datetime.hour
|
170
|
-
else
|
171
|
-
to_time.hour
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
# Returns the minute of the hour (0..59).
|
176
|
-
def min
|
177
|
-
if @time
|
178
|
-
@time.min
|
179
|
-
elsif @datetime
|
180
|
-
@datetime.min
|
181
|
-
else
|
182
|
-
to_time.min
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
# Returns the second of the minute (0..60). (60 for a leap second).
|
187
|
-
def sec
|
188
|
-
if @time
|
189
|
-
@time.sec
|
190
|
-
elsif @datetime
|
191
|
-
@datetime.sec
|
192
|
-
else
|
193
|
-
to_time.sec
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
# Returns the number of microseconds for the time.
|
198
|
-
def usec
|
199
|
-
if @time
|
200
|
-
@time.usec
|
201
|
-
elsif @datetime
|
202
|
-
# Ruby 1.8 has sec_fraction (of which the documentation says
|
203
|
-
# 'I do NOT recommend you to use this method'). sec_fraction no longer
|
204
|
-
# exists in Ruby 1.9.
|
205
|
-
|
206
|
-
# Calculate the sec_fraction from the day_fraction.
|
207
|
-
((@datetime.day_fraction - OffsetRationals.rational_for_offset(@datetime.hour * 3600 + @datetime.min * 60 + @datetime.sec)) * 86400000000).to_i
|
208
|
-
else
|
209
|
-
0
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
# Compares this TimeOrDateTime with another Time, DateTime, timestamp
|
214
|
-
# (Integer) or TimeOrDateTime. Returns -1, 0 or +1 depending
|
215
|
-
# whether the receiver is less than, equal to, or greater than
|
216
|
-
# timeOrDateTime.
|
217
|
-
#
|
218
|
-
# Returns nil if the passed in timeOrDateTime is not comparable with
|
219
|
-
# TimeOrDateTime instances.
|
220
|
-
#
|
221
|
-
# Comparisons involving a DateTime will be performed using DateTime#<=>.
|
222
|
-
# Comparisons that don't involve a DateTime, but include a Time will be
|
223
|
-
# performed with Time#<=>. Otherwise comparisons will be performed with
|
224
|
-
# Integer#<=>.
|
225
|
-
def <=>(timeOrDateTime)
|
226
|
-
return nil unless timeOrDateTime.is_a?(TimeOrDateTime) ||
|
227
|
-
timeOrDateTime.is_a?(Time) ||
|
228
|
-
timeOrDateTime.is_a?(DateTime) ||
|
229
|
-
timeOrDateTime.respond_to?(:to_i)
|
230
|
-
|
231
|
-
unless timeOrDateTime.is_a?(TimeOrDateTime)
|
232
|
-
timeOrDateTime = TimeOrDateTime.wrap(timeOrDateTime)
|
233
|
-
end
|
234
|
-
|
235
|
-
orig = timeOrDateTime.to_orig
|
236
|
-
|
237
|
-
if @orig.is_a?(DateTime) || orig.is_a?(DateTime)
|
238
|
-
# If either is a DateTime, assume it is there for a reason
|
239
|
-
# (i.e. for its larger range of acceptable values on 32-bit systems).
|
240
|
-
to_datetime <=> timeOrDateTime.to_datetime
|
241
|
-
elsif @orig.is_a?(Time) || orig.is_a?(Time)
|
242
|
-
to_time <=> timeOrDateTime.to_time
|
243
|
-
else
|
244
|
-
to_i <=> timeOrDateTime.to_i
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
# Adds a number of seconds to the TimeOrDateTime. Returns a new
|
249
|
-
# TimeOrDateTime, preserving what the original constructed type was.
|
250
|
-
# If the original type is a Time and the resulting calculation goes out of
|
251
|
-
# range for Times, then an exception will be raised by the Time class.
|
252
|
-
def +(seconds)
|
253
|
-
if seconds == 0
|
254
|
-
self
|
255
|
-
else
|
256
|
-
if @orig.is_a?(DateTime)
|
257
|
-
TimeOrDateTime.new(@orig + OffsetRationals.rational_for_offset(seconds))
|
258
|
-
else
|
259
|
-
# + defined for Time and Integer
|
260
|
-
TimeOrDateTime.new(@orig + seconds)
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
# Subtracts a number of seconds from the TimeOrDateTime. Returns a new
|
266
|
-
# TimeOrDateTime, preserving what the original constructed type was.
|
267
|
-
# If the original type is a Time and the resulting calculation goes out of
|
268
|
-
# range for Times, then an exception will be raised by the Time class.
|
269
|
-
def -(seconds)
|
270
|
-
self + (-seconds)
|
271
|
-
end
|
272
|
-
|
273
|
-
# Similar to the + operator, but converts to a DateTime based TimeOrDateTime
|
274
|
-
# where the Time or Integer timestamp to go out of the allowed range for a
|
275
|
-
# Time, converts to a DateTime based TimeOrDateTime.
|
276
|
-
#
|
277
|
-
# Note that the range of Time varies based on the platform.
|
278
|
-
def add_with_convert(seconds)
|
279
|
-
if seconds == 0
|
280
|
-
self
|
281
|
-
else
|
282
|
-
if @orig.is_a?(DateTime)
|
283
|
-
TimeOrDateTime.new(@orig + OffsetRationals.rational_for_offset(seconds))
|
284
|
-
else
|
285
|
-
# A Time or timestamp.
|
286
|
-
result = to_i + seconds
|
287
|
-
|
288
|
-
if ((result > 2147483647 || result < -2147483648) && !RubyCoreSupport.time_supports_64bit) || (result < 0 && !RubyCoreSupport.time_supports_negative)
|
289
|
-
result = TimeOrDateTime.new(to_datetime + OffsetRationals.rational_for_offset(seconds))
|
290
|
-
else
|
291
|
-
result = TimeOrDateTime.new(@orig + seconds)
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
# Returns true if todt represents the same time and was originally
|
298
|
-
# constructed with the same type (DateTime, Time or timestamp) as this
|
299
|
-
# TimeOrDateTime.
|
300
|
-
def eql?(todt)
|
301
|
-
todt.kind_of?(TimeOrDateTime) && to_orig.eql?(todt.to_orig)
|
302
|
-
end
|
303
|
-
|
304
|
-
# Returns a hash of this TimeOrDateTime.
|
305
|
-
def hash
|
306
|
-
@orig.hash
|
307
|
-
end
|
308
|
-
|
309
|
-
# If no block is given, returns a TimeOrDateTime wrapping the given
|
310
|
-
# timeOrDateTime. If a block is specified, a TimeOrDateTime is constructed
|
311
|
-
# and passed to the block. The result of the block must be a TimeOrDateTime.
|
312
|
-
#
|
313
|
-
# The result of the block will be converted to the type of the originally
|
314
|
-
# passed in timeOrDateTime and then returned as the result of wrap.
|
315
|
-
#
|
316
|
-
# timeOrDateTime can be a Time, DateTime, timestamp (Integer) or
|
317
|
-
# TimeOrDateTime. If a TimeOrDateTime is passed in, no new TimeOrDateTime
|
318
|
-
# will be constructed and the value passed to wrap will be used when
|
319
|
-
# calling the block.
|
320
|
-
def self.wrap(timeOrDateTime)
|
321
|
-
t = timeOrDateTime.is_a?(TimeOrDateTime) ? timeOrDateTime : TimeOrDateTime.new(timeOrDateTime)
|
322
|
-
|
323
|
-
if block_given?
|
324
|
-
t = yield t
|
325
|
-
|
326
|
-
if timeOrDateTime.is_a?(TimeOrDateTime)
|
327
|
-
t
|
328
|
-
elsif timeOrDateTime.is_a?(Time)
|
329
|
-
t.to_time
|
330
|
-
elsif timeOrDateTime.is_a?(DateTime)
|
331
|
-
t.to_datetime
|
332
|
-
else
|
333
|
-
t.to_i
|
334
|
-
end
|
335
|
-
else
|
336
|
-
t
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|
340
|
-
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
|
data/lib/tzinfo/timezone_info.rb
DELETED
@@ -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
|