tzinfo 1.2.9 → 2.0.6
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/.yardopts +3 -0
- data/CHANGES.md +589 -387
- data/LICENSE +13 -13
- data/README.md +368 -114
- data/lib/tzinfo/annual_rules.rb +32 -12
- data/lib/tzinfo/country.rb +141 -129
- data/lib/tzinfo/country_timezone.rb +70 -112
- data/lib/tzinfo/data_source.rb +400 -144
- 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/posix_time_zone_parser.rb +177 -0
- data/lib/tzinfo/data_sources/ruby_data_source.rb +141 -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 +592 -0
- data/lib/tzinfo/data_sources/zoneinfo_reader.rb +482 -0
- data/lib/tzinfo/data_sources.rb +8 -0
- data/lib/tzinfo/data_timezone.rb +33 -47
- data/lib/tzinfo/datetime_with_offset.rb +153 -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/format1.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/format2.rb +10 -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/ruby_core_support.rb +24 -155
- data/lib/tzinfo/string_deduper.rb +118 -0
- data/lib/tzinfo/time_with_offset.rb +154 -0
- data/lib/tzinfo/timestamp.rb +552 -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/transition_rule.rb +207 -77
- data/lib/tzinfo/transitions_timezone_period.rb +63 -0
- data/lib/tzinfo/version.rb +7 -0
- data/lib/tzinfo/with_offset.rb +61 -0
- data/lib/tzinfo.rb +78 -40
- data.tar.gz.sig +0 -0
- metadata +50 -104
- 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/posix_time_zone_parser.rb +0 -136
- data/lib/tzinfo/ruby_country_info.rb +0 -74
- data/lib/tzinfo/ruby_data_source.rb +0 -140
- data/lib/tzinfo/time_or_datetime.rb +0 -351
- 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 -497
- data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -520
- data/test/tc_annual_rules.rb +0 -95
- data/test/tc_country.rb +0 -238
- 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_posix_time_zone_parser.rb +0 -261
- 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 -167
- data/test/tc_time_or_datetime.rb +0 -674
- data/test/tc_timezone.rb +0 -1361
- 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_transition_rule.rb +0 -663
- 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 -2153
- data/test/test_utils.rb +0 -192
- 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/definitions/America/Argentina/Buenos_Aires.rb +0 -89
- data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +0 -327
- data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +0 -230
- 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 -273
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +0 -198
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +0 -333
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +0 -277
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +0 -235
- data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +0 -16
- data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +0 -940
- data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +0 -609
- data/test/tzinfo-data/tzinfo/data/version.rb +0 -20
- data/test/tzinfo-data/tzinfo/data.rb +0 -8
- 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 -274
- data/test/zoneinfo/leapseconds +0 -78
- 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 -452
- data/test/zoneinfo/zone1970.tab +0 -384
- data/tzinfo.gemspec +0 -21
@@ -0,0 +1,118 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'concurrent'
|
5
|
+
|
6
|
+
module TZInfo
|
7
|
+
# Maintains a pool of `String` instances. The {#dedupe} method will return
|
8
|
+
# either a pooled copy of a given `String` or add the instance to the pool.
|
9
|
+
#
|
10
|
+
# @private
|
11
|
+
class StringDeduper #:nodoc:
|
12
|
+
class << self
|
13
|
+
# @return [StringDeduper] a globally available singleton instance of
|
14
|
+
# {StringDeduper}. This instance is safe for use in concurrently
|
15
|
+
# executing threads.
|
16
|
+
attr_reader :global
|
17
|
+
end
|
18
|
+
|
19
|
+
# Initializes a new {StringDeduper}.
|
20
|
+
def initialize
|
21
|
+
@strings = create_hash do |h, k|
|
22
|
+
v = k.dup.freeze
|
23
|
+
h[v] = v
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param string [String] the string to deduplicate.
|
28
|
+
# @return [bool] `string` if it is frozen, otherwise a frozen, possibly
|
29
|
+
# pre-existing copy of `string`.
|
30
|
+
def dedupe(string)
|
31
|
+
return string if string.frozen?
|
32
|
+
@strings[string]
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
# Creates a `Hash` to store pooled `String` instances.
|
38
|
+
#
|
39
|
+
# @param block [Proc] Default value block to be passed to `Hash.new`.
|
40
|
+
# @return [Hash] a `Hash` to store pooled `String` instances.
|
41
|
+
def create_hash(&block)
|
42
|
+
Hash.new(&block)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
private_constant :StringDeduper
|
46
|
+
|
47
|
+
# A thread-safe version of {StringDeduper}.
|
48
|
+
#
|
49
|
+
# @private
|
50
|
+
class ConcurrentStringDeduper < StringDeduper #:nodoc:
|
51
|
+
protected
|
52
|
+
|
53
|
+
def create_hash(&block)
|
54
|
+
Concurrent::Map.new(&block)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
private_constant :ConcurrentStringDeduper
|
58
|
+
|
59
|
+
|
60
|
+
string_unary_minus_does_dedupe = if '0'.respond_to?(:-@)
|
61
|
+
# :nocov_no_string_-@:
|
62
|
+
s1 = -('0'.dup)
|
63
|
+
s2 = -('0'.dup)
|
64
|
+
s1.object_id == s2.object_id
|
65
|
+
# :nocov_no_string_-@:
|
66
|
+
else
|
67
|
+
# :nocov_string_-@:
|
68
|
+
false
|
69
|
+
# :nocov_string_-@:
|
70
|
+
end
|
71
|
+
|
72
|
+
if string_unary_minus_does_dedupe
|
73
|
+
# :nocov_no_deduping_string_unary_minus:
|
74
|
+
|
75
|
+
# An implementation of {StringDeduper} using the `String#-@` method where
|
76
|
+
# that method performs deduplication (Ruby 2.5 and later).
|
77
|
+
#
|
78
|
+
# Note that this is slightly different to the plain {StringDeduper}
|
79
|
+
# implementation. In this implementation, frozen literal strings are already
|
80
|
+
# in the pool and are candidates for being returned, even when passed
|
81
|
+
# another equal frozen non-literal string. {StringDeduper} will always
|
82
|
+
# return frozen strings.
|
83
|
+
#
|
84
|
+
# There are also differences in encoding handling. This implementation will
|
85
|
+
# treat strings with different encodings as different strings.
|
86
|
+
# {StringDeduper} will treat strings with the compatible encodings as the
|
87
|
+
# same string.
|
88
|
+
#
|
89
|
+
# @private
|
90
|
+
class UnaryMinusGlobalStringDeduper #:nodoc:
|
91
|
+
# @param string [String] the string to deduplicate.
|
92
|
+
# @return [bool] `string` if it is frozen, otherwise a frozen, possibly
|
93
|
+
# pre-existing copy of `string`.
|
94
|
+
def dedupe(string)
|
95
|
+
# String#-@ on Ruby 2.6 will dedupe a frozen non-literal String. Ruby
|
96
|
+
# 2.5 will just return frozen strings.
|
97
|
+
#
|
98
|
+
# The pooled implementation can't tell the difference between frozen
|
99
|
+
# literals and frozen non-literals, so must always return frozen String
|
100
|
+
# instances to avoid doing unncessary work when loading format 2
|
101
|
+
# TZInfo::Data modules.
|
102
|
+
#
|
103
|
+
# For compatibility with the pooled implementation, just return frozen
|
104
|
+
# string instances (acting like Ruby 2.5).
|
105
|
+
return string if string.frozen?
|
106
|
+
-string
|
107
|
+
end
|
108
|
+
end
|
109
|
+
private_constant :UnaryMinusGlobalStringDeduper
|
110
|
+
|
111
|
+
StringDeduper.instance_variable_set(:@global, UnaryMinusGlobalStringDeduper.new)
|
112
|
+
# :nocov_no_deduping_string_unary_minus:
|
113
|
+
else
|
114
|
+
# :nocov_deduping_string_unary_minus:
|
115
|
+
StringDeduper.instance_variable_set(:@global, ConcurrentStringDeduper.new)
|
116
|
+
# :nocov_deduping_string_unary_minus:
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module TZInfo
|
5
|
+
# A subclass of `Time` used to represent local times. {TimeWithOffset} holds a
|
6
|
+
# reference to the related {TimezoneOffset} and overrides various methods to
|
7
|
+
# return results appropriate for the {TimezoneOffset}. Certain operations will
|
8
|
+
# clear the associated {TimezoneOffset} (if the {TimezoneOffset} would not
|
9
|
+
# necessarily be valid for the result). Once the {TimezoneOffset} has been
|
10
|
+
# cleared, {TimeWithOffset} behaves identically to `Time`.
|
11
|
+
#
|
12
|
+
# Arithmetic performed on {TimeWithOffset} instances is _not_ time zone-aware.
|
13
|
+
# Regardless of whether transitions in the time zone are crossed, results of
|
14
|
+
# arithmetic operations will always maintain the same offset from UTC
|
15
|
+
# (`utc_offset`). The associated {TimezoneOffset} will aways be cleared.
|
16
|
+
class TimeWithOffset < Time
|
17
|
+
include WithOffset
|
18
|
+
|
19
|
+
# @return [TimezoneOffset] the {TimezoneOffset} associated with this
|
20
|
+
# instance.
|
21
|
+
attr_reader :timezone_offset
|
22
|
+
|
23
|
+
# Marks this {TimeWithOffset} as a local time with the UTC offset of a given
|
24
|
+
# {TimezoneOffset} and sets the associated {TimezoneOffset}.
|
25
|
+
#
|
26
|
+
# @param timezone_offset [TimezoneOffset] the {TimezoneOffset} to use to set
|
27
|
+
# the offset of this {TimeWithOffset}.
|
28
|
+
# @return [TimeWithOffset] `self`.
|
29
|
+
# @raise [ArgumentError] if `timezone_offset` is `nil`.
|
30
|
+
def set_timezone_offset(timezone_offset)
|
31
|
+
raise ArgumentError, 'timezone_offset must be specified' unless timezone_offset
|
32
|
+
localtime(timezone_offset.observed_utc_offset)
|
33
|
+
@timezone_offset = timezone_offset
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
# An overridden version of `Time#dst?` that, if there is an associated
|
38
|
+
# {TimezoneOffset}, returns the result of calling {TimezoneOffset#dst? dst?}
|
39
|
+
# on that offset.
|
40
|
+
#
|
41
|
+
# @return [Boolean] `true` if daylight savings time is being observed,
|
42
|
+
# otherwise `false`.
|
43
|
+
def dst?
|
44
|
+
to = timezone_offset
|
45
|
+
to ? to.dst? : super
|
46
|
+
end
|
47
|
+
alias isdst dst?
|
48
|
+
|
49
|
+
# An overridden version of `Time#getlocal` that clears the associated
|
50
|
+
# {TimezoneOffset} if the base implementation of `getlocal` returns a
|
51
|
+
# {TimeWithOffset}.
|
52
|
+
#
|
53
|
+
# @return [Time] a representation of the {TimeWithOffset} using either the
|
54
|
+
# local time zone or the given offset.
|
55
|
+
def getlocal(*args)
|
56
|
+
# JRuby < 9.3 returns a Time in all cases.
|
57
|
+
# JRuby >= 9.3 returns a Time when called with no arguments and a
|
58
|
+
# TimeWithOffset with a timezone_offset assigned when called with an
|
59
|
+
# offset argument.
|
60
|
+
result = super
|
61
|
+
result.clear_timezone_offset if result.kind_of?(TimeWithOffset)
|
62
|
+
result
|
63
|
+
end
|
64
|
+
|
65
|
+
# An overridden version of `Time#gmtime` that clears the associated
|
66
|
+
# {TimezoneOffset}.
|
67
|
+
#
|
68
|
+
# @return [TimeWithOffset] `self`.
|
69
|
+
def gmtime
|
70
|
+
super
|
71
|
+
@timezone_offset = nil
|
72
|
+
self
|
73
|
+
end
|
74
|
+
|
75
|
+
# An overridden version of `Time#localtime` that clears the associated
|
76
|
+
# {TimezoneOffset}.
|
77
|
+
#
|
78
|
+
# @return [TimeWithOffset] `self`.
|
79
|
+
def localtime(*args)
|
80
|
+
super
|
81
|
+
@timezone_offset = nil
|
82
|
+
self
|
83
|
+
end
|
84
|
+
|
85
|
+
# An overridden version of `Time#round` that, if there is an associated
|
86
|
+
# {TimezoneOffset}, returns a {TimeWithOffset} preserving that offset.
|
87
|
+
#
|
88
|
+
# @return [Time] the rounded time.
|
89
|
+
def round(ndigits = 0)
|
90
|
+
if_timezone_offset(super) {|o,t| self.class.at(t.to_i, t.subsec * 1_000_000).set_timezone_offset(o) }
|
91
|
+
end
|
92
|
+
|
93
|
+
# An overridden version of `Time#to_a`. The `isdst` (index 8) and `zone`
|
94
|
+
# (index 9) elements of the array are set according to the associated
|
95
|
+
# {TimezoneOffset}.
|
96
|
+
#
|
97
|
+
# @return [Array] an `Array` representation of the {TimeWithOffset}.
|
98
|
+
def to_a
|
99
|
+
if_timezone_offset(super) do |o,a|
|
100
|
+
a[8] = o.dst?
|
101
|
+
a[9] = o.abbreviation
|
102
|
+
a
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# An overridden version of `Time#utc` that clears the associated
|
107
|
+
# {TimezoneOffset}.
|
108
|
+
#
|
109
|
+
# @return [TimeWithOffset] `self`.
|
110
|
+
def utc
|
111
|
+
super
|
112
|
+
@timezone_offset = nil
|
113
|
+
self
|
114
|
+
end
|
115
|
+
|
116
|
+
# An overridden version of `Time#zone` that, if there is an associated
|
117
|
+
# {TimezoneOffset}, returns the {TimezoneOffset#abbreviation abbreviation}
|
118
|
+
# of that offset.
|
119
|
+
#
|
120
|
+
# @return [String] the {TimezoneOffset#abbreviation abbreviation} of the
|
121
|
+
# associated {TimezoneOffset}, or the result from `Time#zone` if there is
|
122
|
+
# no such offset.
|
123
|
+
def zone
|
124
|
+
to = timezone_offset
|
125
|
+
to ? to.abbreviation : super
|
126
|
+
end
|
127
|
+
|
128
|
+
# An overridden version of `Time#to_datetime` that, if there is an
|
129
|
+
# associated {TimezoneOffset}, returns a {DateTimeWithOffset} with that
|
130
|
+
# offset.
|
131
|
+
#
|
132
|
+
# @return [DateTime] if there is an associated {TimezoneOffset}, a
|
133
|
+
# {DateTimeWithOffset} representation of this {TimeWithOffset}, otherwise
|
134
|
+
# a `Time` representation.
|
135
|
+
def to_datetime
|
136
|
+
if_timezone_offset(super) do |o,dt|
|
137
|
+
offset = dt.offset
|
138
|
+
result = DateTimeWithOffset.jd(dt.jd + dt.day_fraction - offset)
|
139
|
+
result = result.new_offset(offset) unless offset == 0
|
140
|
+
result.set_timezone_offset(o)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
protected
|
145
|
+
|
146
|
+
# Clears the associated {TimezoneOffset}.
|
147
|
+
#
|
148
|
+
# @return [TimeWithOffset] `self`.
|
149
|
+
def clear_timezone_offset
|
150
|
+
@timezone_offset = nil
|
151
|
+
self
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|