tzinfo 1.2.5
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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +0 -0
- data/.yardopts +6 -0
- data/CHANGES.md +786 -0
- data/LICENSE +19 -0
- data/README.md +151 -0
- data/Rakefile +107 -0
- data/lib/tzinfo.rb +40 -0
- data/lib/tzinfo/country.rb +196 -0
- data/lib/tzinfo/country_index_definition.rb +31 -0
- data/lib/tzinfo/country_info.rb +42 -0
- data/lib/tzinfo/country_timezone.rb +135 -0
- data/lib/tzinfo/data_source.rb +190 -0
- data/lib/tzinfo/data_timezone.rb +58 -0
- data/lib/tzinfo/data_timezone_info.rb +55 -0
- data/lib/tzinfo/info_timezone.rb +30 -0
- data/lib/tzinfo/linked_timezone.rb +63 -0
- data/lib/tzinfo/linked_timezone_info.rb +26 -0
- data/lib/tzinfo/offset_rationals.rb +77 -0
- data/lib/tzinfo/ruby_core_support.rb +146 -0
- data/lib/tzinfo/ruby_country_info.rb +74 -0
- data/lib/tzinfo/ruby_data_source.rb +136 -0
- data/lib/tzinfo/time_or_datetime.rb +340 -0
- data/lib/tzinfo/timezone.rb +669 -0
- data/lib/tzinfo/timezone_definition.rb +36 -0
- data/lib/tzinfo/timezone_index_definition.rb +54 -0
- data/lib/tzinfo/timezone_info.rb +30 -0
- data/lib/tzinfo/timezone_offset.rb +101 -0
- data/lib/tzinfo/timezone_period.rb +245 -0
- data/lib/tzinfo/timezone_proxy.rb +105 -0
- data/lib/tzinfo/timezone_transition.rb +130 -0
- data/lib/tzinfo/timezone_transition_definition.rb +104 -0
- data/lib/tzinfo/transition_data_timezone_info.rb +274 -0
- data/lib/tzinfo/zoneinfo_country_info.rb +37 -0
- data/lib/tzinfo/zoneinfo_data_source.rb +488 -0
- data/lib/tzinfo/zoneinfo_timezone_info.rb +296 -0
- data/test/tc_country.rb +234 -0
- data/test/tc_country_index_definition.rb +69 -0
- data/test/tc_country_info.rb +16 -0
- data/test/tc_country_timezone.rb +173 -0
- data/test/tc_data_source.rb +218 -0
- data/test/tc_data_timezone.rb +99 -0
- data/test/tc_data_timezone_info.rb +18 -0
- data/test/tc_info_timezone.rb +34 -0
- data/test/tc_linked_timezone.rb +155 -0
- data/test/tc_linked_timezone_info.rb +23 -0
- data/test/tc_offset_rationals.rb +23 -0
- data/test/tc_ruby_core_support.rb +168 -0
- data/test/tc_ruby_country_info.rb +110 -0
- data/test/tc_ruby_data_source.rb +143 -0
- data/test/tc_time_or_datetime.rb +654 -0
- data/test/tc_timezone.rb +1350 -0
- data/test/tc_timezone_definition.rb +113 -0
- data/test/tc_timezone_index_definition.rb +73 -0
- data/test/tc_timezone_info.rb +11 -0
- data/test/tc_timezone_london.rb +143 -0
- data/test/tc_timezone_melbourne.rb +142 -0
- data/test/tc_timezone_new_york.rb +142 -0
- data/test/tc_timezone_offset.rb +126 -0
- data/test/tc_timezone_period.rb +555 -0
- data/test/tc_timezone_proxy.rb +136 -0
- data/test/tc_timezone_transition.rb +366 -0
- data/test/tc_timezone_transition_definition.rb +295 -0
- data/test/tc_timezone_utc.rb +27 -0
- data/test/tc_transition_data_timezone_info.rb +423 -0
- data/test/tc_zoneinfo_country_info.rb +78 -0
- data/test/tc_zoneinfo_data_source.rb +1195 -0
- data/test/tc_zoneinfo_timezone_info.rb +1232 -0
- data/test/test_utils.rb +163 -0
- data/test/ts_all.rb +7 -0
- data/test/ts_all_ruby.rb +5 -0
- data/test/ts_all_zoneinfo.rb +7 -0
- data/test/tzinfo-data/tzinfo/data.rb +8 -0
- data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +89 -0
- data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +315 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +218 -0
- data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +19 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +21 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +21 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +21 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +261 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +186 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +321 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +265 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +220 -0
- data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +16 -0
- data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +927 -0
- data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +596 -0
- data/test/tzinfo-data/tzinfo/data/version.rb +14 -0
- 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 +275 -0
- data/test/zoneinfo/leapseconds +61 -0
- 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 +439 -0
- data/test/zoneinfo/zone1970.tab +369 -0
- data/tzinfo.gemspec +21 -0
- metadata +193 -0
- metadata.gz.sig +2 -0
@@ -0,0 +1,36 @@
|
|
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
|
@@ -0,0 +1,54 @@
|
|
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
|
@@ -0,0 +1,30 @@
|
|
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
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module TZInfo
|
2
|
+
# Represents an offset defined in a Timezone data file.
|
3
|
+
class TimezoneOffset
|
4
|
+
# The base offset of the timezone from UTC in seconds. This does not include
|
5
|
+
# any adjustment made for daylight savings time and will typically remain
|
6
|
+
# constant throughout the year.
|
7
|
+
#
|
8
|
+
# To obtain the currently observed offset from UTC, including the effect of
|
9
|
+
# daylight savings time, use utc_total_offset instead.
|
10
|
+
#
|
11
|
+
# Note that zoneinfo files only include the value of utc_total_offset and a
|
12
|
+
# DST flag. When using ZoneinfoDataSource, the utc_offset will be derived
|
13
|
+
# from changes to the UTC total offset and the DST flag. As a consequence,
|
14
|
+
# utc_total_offset will always be correct, but utc_offset may be inaccurate.
|
15
|
+
#
|
16
|
+
# If you require utc_offset to be accurate, install the tzinfo-data gem and
|
17
|
+
# set RubyDataSource as the DataSource.
|
18
|
+
attr_reader :utc_offset
|
19
|
+
|
20
|
+
# The offset from the time zone's standard time in seconds. Zero
|
21
|
+
# when daylight savings time is not in effect. Non-zero (usually 3600 = 1
|
22
|
+
# hour) if daylight savings is being observed.
|
23
|
+
#
|
24
|
+
# Note that zoneinfo files only include the value of utc_total_offset and
|
25
|
+
# a DST flag. When using DataSources::ZoneinfoDataSource, the std_offset
|
26
|
+
# will be derived from changes to the UTC total offset and the DST flag. As
|
27
|
+
# a consequence, utc_total_offset will always be correct, but std_offset
|
28
|
+
# may be inaccurate.
|
29
|
+
#
|
30
|
+
# If you require std_offset to be accurate, install the tzinfo-data gem
|
31
|
+
# and set RubyDataSource as the DataSource.
|
32
|
+
attr_reader :std_offset
|
33
|
+
|
34
|
+
# The total offset of this observance from UTC in seconds
|
35
|
+
# (utc_offset + std_offset).
|
36
|
+
attr_reader :utc_total_offset
|
37
|
+
|
38
|
+
# The abbreviation that identifies this observance, e.g. "GMT"
|
39
|
+
# (Greenwich Mean Time) or "BST" (British Summer Time) for "Europe/London". The returned identifier is a
|
40
|
+
# symbol.
|
41
|
+
attr_reader :abbreviation
|
42
|
+
|
43
|
+
# Constructs a new TimezoneOffset. utc_offset and std_offset are specified
|
44
|
+
# in seconds.
|
45
|
+
def initialize(utc_offset, std_offset, abbreviation)
|
46
|
+
@utc_offset = utc_offset
|
47
|
+
@std_offset = std_offset
|
48
|
+
@abbreviation = abbreviation
|
49
|
+
|
50
|
+
@utc_total_offset = @utc_offset + @std_offset
|
51
|
+
end
|
52
|
+
|
53
|
+
# True if std_offset is non-zero.
|
54
|
+
def dst?
|
55
|
+
@std_offset != 0
|
56
|
+
end
|
57
|
+
|
58
|
+
# Converts a UTC Time, DateTime or integer timestamp to local time, based on
|
59
|
+
# the offset of this period.
|
60
|
+
#
|
61
|
+
# Deprecation warning: this method will be removed in TZInfo version 2.0.0.
|
62
|
+
def to_local(utc)
|
63
|
+
TimeOrDateTime.wrap(utc) {|wrapped|
|
64
|
+
wrapped + @utc_total_offset
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
# Converts a local Time, DateTime or integer timestamp to UTC, based on the
|
69
|
+
# offset of this period.
|
70
|
+
#
|
71
|
+
# Deprecation warning: this method will be removed in TZInfo version 2.0.0.
|
72
|
+
def to_utc(local)
|
73
|
+
TimeOrDateTime.wrap(local) {|wrapped|
|
74
|
+
wrapped - @utc_total_offset
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns true if and only if toi has the same utc_offset, std_offset
|
79
|
+
# and abbreviation as this TimezoneOffset.
|
80
|
+
def ==(toi)
|
81
|
+
toi.kind_of?(TimezoneOffset) &&
|
82
|
+
utc_offset == toi.utc_offset && std_offset == toi.std_offset && abbreviation == toi.abbreviation
|
83
|
+
end
|
84
|
+
|
85
|
+
# Returns true if and only if toi has the same utc_offset, std_offset
|
86
|
+
# and abbreviation as this TimezoneOffset.
|
87
|
+
def eql?(toi)
|
88
|
+
self == toi
|
89
|
+
end
|
90
|
+
|
91
|
+
# Returns a hash of this TimezoneOffset.
|
92
|
+
def hash
|
93
|
+
utc_offset.hash ^ std_offset.hash ^ abbreviation.hash
|
94
|
+
end
|
95
|
+
|
96
|
+
# Returns internal object state as a programmer-readable string.
|
97
|
+
def inspect
|
98
|
+
"#<#{self.class}: #@utc_offset,#@std_offset,#@abbreviation>"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,245 @@
|
|
1
|
+
module TZInfo
|
2
|
+
# A period of time in a timezone where the same offset from UTC applies.
|
3
|
+
#
|
4
|
+
# All the methods that take times accept instances of Time or DateTime as well
|
5
|
+
# as Integer timestamps.
|
6
|
+
class TimezonePeriod
|
7
|
+
# The TimezoneTransition that defines the start of this TimezonePeriod
|
8
|
+
# (may be nil if unbounded).
|
9
|
+
attr_reader :start_transition
|
10
|
+
|
11
|
+
# The TimezoneTransition that defines the end of this TimezonePeriod
|
12
|
+
# (may be nil if unbounded).
|
13
|
+
attr_reader :end_transition
|
14
|
+
|
15
|
+
# The TimezoneOffset for this period.
|
16
|
+
attr_reader :offset
|
17
|
+
|
18
|
+
# Initializes a new TimezonePeriod.
|
19
|
+
#
|
20
|
+
# TimezonePeriod instances should not normally be constructed manually.
|
21
|
+
def initialize(start_transition, end_transition, offset = nil)
|
22
|
+
@start_transition = start_transition
|
23
|
+
@end_transition = end_transition
|
24
|
+
|
25
|
+
if offset
|
26
|
+
raise ArgumentError, 'Offset specified with transitions' if @start_transition || @end_transition
|
27
|
+
@offset = offset
|
28
|
+
else
|
29
|
+
if @start_transition
|
30
|
+
@offset = @start_transition.offset
|
31
|
+
elsif @end_transition
|
32
|
+
@offset = @end_transition.previous_offset
|
33
|
+
else
|
34
|
+
raise ArgumentError, 'No offset specified and no transitions to determine it from'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
@utc_total_offset_rational = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
# The base offset of the timezone from UTC in seconds. This does not include
|
42
|
+
# any adjustment made for daylight savings time and will typically remain
|
43
|
+
# constant throughout the year.
|
44
|
+
#
|
45
|
+
# To obtain the currently observed offset from UTC, including the effect of
|
46
|
+
# daylight savings time, use utc_total_offset instead.
|
47
|
+
#
|
48
|
+
# Note that zoneinfo files only include the value of utc_total_offset and a
|
49
|
+
# DST flag. When using ZoneinfoDataSource, the utc_offset will be derived
|
50
|
+
# from changes to the UTC total offset and the DST flag. As a consequence,
|
51
|
+
# utc_total_offset will always be correct, but utc_offset may be inaccurate.
|
52
|
+
#
|
53
|
+
# If you require utc_offset to be accurate, install the tzinfo-data gem and
|
54
|
+
# set RubyDataSource as the DataSource.
|
55
|
+
def utc_offset
|
56
|
+
@offset.utc_offset
|
57
|
+
end
|
58
|
+
|
59
|
+
# The offset from the time zone's standard time in seconds. Zero
|
60
|
+
# when daylight savings time is not in effect. Non-zero (usually 3600 = 1
|
61
|
+
# hour) if daylight savings is being observed.
|
62
|
+
#
|
63
|
+
# Note that zoneinfo files only include the value of utc_total_offset and
|
64
|
+
# a DST flag. When using DataSources::ZoneinfoDataSource, the std_offset
|
65
|
+
# will be derived from changes to the UTC total offset and the DST flag. As
|
66
|
+
# a consequence, utc_total_offset will always be correct, but std_offset
|
67
|
+
# may be inaccurate.
|
68
|
+
#
|
69
|
+
# If you require std_offset to be accurate, install the tzinfo-data gem
|
70
|
+
# and set RubyDataSource as the DataSource.
|
71
|
+
def std_offset
|
72
|
+
@offset.std_offset
|
73
|
+
end
|
74
|
+
|
75
|
+
# The identifier of this period, e.g. "GMT" (Greenwich Mean Time) or "BST"
|
76
|
+
# (British Summer Time) for "Europe/London". The returned identifier is a
|
77
|
+
# symbol.
|
78
|
+
def abbreviation
|
79
|
+
@offset.abbreviation
|
80
|
+
end
|
81
|
+
alias :zone_identifier :abbreviation
|
82
|
+
|
83
|
+
# Total offset from UTC (seconds). Equal to utc_offset + std_offset.
|
84
|
+
def utc_total_offset
|
85
|
+
@offset.utc_total_offset
|
86
|
+
end
|
87
|
+
|
88
|
+
# Total offset from UTC (days). Result is a Rational.
|
89
|
+
def utc_total_offset_rational
|
90
|
+
# Thread-safety: It is possible that the value of
|
91
|
+
# @utc_total_offset_rational may be calculated multiple times in
|
92
|
+
# concurrently executing threads. It is not worth the overhead of locking
|
93
|
+
# to ensure that @zone_identifiers is only calculated once.
|
94
|
+
|
95
|
+
unless @utc_total_offset_rational
|
96
|
+
result = OffsetRationals.rational_for_offset(utc_total_offset)
|
97
|
+
return result if frozen?
|
98
|
+
@utc_total_offset_rational = result
|
99
|
+
end
|
100
|
+
@utc_total_offset_rational
|
101
|
+
end
|
102
|
+
|
103
|
+
# The start time of the period in UTC as a DateTime. May be nil if unbounded.
|
104
|
+
def utc_start
|
105
|
+
@start_transition ? @start_transition.at.to_datetime : nil
|
106
|
+
end
|
107
|
+
|
108
|
+
# The start time of the period in UTC as a Time. May be nil if unbounded.
|
109
|
+
def utc_start_time
|
110
|
+
@start_transition ? @start_transition.at.to_time : nil
|
111
|
+
end
|
112
|
+
|
113
|
+
# The end time of the period in UTC as a DateTime. May be nil if unbounded.
|
114
|
+
def utc_end
|
115
|
+
@end_transition ? @end_transition.at.to_datetime : nil
|
116
|
+
end
|
117
|
+
|
118
|
+
# The end time of the period in UTC as a Time. May be nil if unbounded.
|
119
|
+
def utc_end_time
|
120
|
+
@end_transition ? @end_transition.at.to_time : nil
|
121
|
+
end
|
122
|
+
|
123
|
+
# The start time of the period in local time as a DateTime. May be nil if
|
124
|
+
# unbounded.
|
125
|
+
def local_start
|
126
|
+
@start_transition ? @start_transition.local_start_at.to_datetime : nil
|
127
|
+
end
|
128
|
+
|
129
|
+
# The start time of the period in local time as a Time. May be nil if
|
130
|
+
# unbounded.
|
131
|
+
def local_start_time
|
132
|
+
@start_transition ? @start_transition.local_start_at.to_time : nil
|
133
|
+
end
|
134
|
+
|
135
|
+
# The end time of the period in local time as a DateTime. May be nil if
|
136
|
+
# unbounded.
|
137
|
+
def local_end
|
138
|
+
@end_transition ? @end_transition.local_end_at.to_datetime : nil
|
139
|
+
end
|
140
|
+
|
141
|
+
# The end time of the period in local time as a Time. May be nil if
|
142
|
+
# unbounded.
|
143
|
+
def local_end_time
|
144
|
+
@end_transition ? @end_transition.local_end_at.to_time : nil
|
145
|
+
end
|
146
|
+
|
147
|
+
# true if daylight savings is in effect for this period; otherwise false.
|
148
|
+
def dst?
|
149
|
+
@offset.dst?
|
150
|
+
end
|
151
|
+
|
152
|
+
# true if this period is valid for the given UTC DateTime; otherwise false.
|
153
|
+
#
|
154
|
+
# Deprecation warning: this method will be removed in TZInfo version 2.0.0.
|
155
|
+
def valid_for_utc?(utc)
|
156
|
+
utc_after_start?(utc) && utc_before_end?(utc)
|
157
|
+
end
|
158
|
+
|
159
|
+
# true if the given UTC DateTime is after the start of the period
|
160
|
+
# (inclusive); otherwise false.
|
161
|
+
#
|
162
|
+
# Deprecation warning: this method will be removed in TZInfo version 2.0.0.
|
163
|
+
def utc_after_start?(utc)
|
164
|
+
!@start_transition || @start_transition.at <= utc
|
165
|
+
end
|
166
|
+
|
167
|
+
# true if the given UTC DateTime is before the end of the period
|
168
|
+
# (exclusive); otherwise false.
|
169
|
+
#
|
170
|
+
# Deprecation warning: this method will be removed in TZInfo version 2.0.0.
|
171
|
+
def utc_before_end?(utc)
|
172
|
+
!@end_transition || @end_transition.at > utc
|
173
|
+
end
|
174
|
+
|
175
|
+
# true if this period is valid for the given local DateTime; otherwise
|
176
|
+
# false.
|
177
|
+
#
|
178
|
+
# Deprecation warning: this method will be removed in TZInfo version 2.0.0.
|
179
|
+
def valid_for_local?(local)
|
180
|
+
local_after_start?(local) && local_before_end?(local)
|
181
|
+
end
|
182
|
+
|
183
|
+
# true if the given local DateTime is after the start of the period
|
184
|
+
# (inclusive); otherwise false.
|
185
|
+
#
|
186
|
+
# Deprecation warning: this method will be removed in TZInfo version 2.0.0.
|
187
|
+
def local_after_start?(local)
|
188
|
+
!@start_transition || @start_transition.local_start_at <= local
|
189
|
+
end
|
190
|
+
|
191
|
+
# true if the given local DateTime is before the end of the period
|
192
|
+
# (exclusive); otherwise false.
|
193
|
+
#
|
194
|
+
# Deprecation warning: this method will be removed in TZInfo version 2.0.0.
|
195
|
+
def local_before_end?(local)
|
196
|
+
!@end_transition || @end_transition.local_end_at > local
|
197
|
+
end
|
198
|
+
|
199
|
+
# Converts a UTC DateTime to local time based on the offset of this period.
|
200
|
+
#
|
201
|
+
# Deprecation warning: this method will be removed in TZInfo version 2.0.0.
|
202
|
+
def to_local(utc)
|
203
|
+
@offset.to_local(utc)
|
204
|
+
end
|
205
|
+
|
206
|
+
# Converts a local DateTime to UTC based on the offset of this period.
|
207
|
+
#
|
208
|
+
# Deprecation warning: this method will be removed in TZInfo version 2.0.0.
|
209
|
+
def to_utc(local)
|
210
|
+
@offset.to_utc(local)
|
211
|
+
end
|
212
|
+
|
213
|
+
# Returns true if this TimezonePeriod is equal to p. This compares the
|
214
|
+
# start_transition, end_transition and offset using ==.
|
215
|
+
def ==(p)
|
216
|
+
p.kind_of?(TimezonePeriod) &&
|
217
|
+
start_transition == p.start_transition &&
|
218
|
+
end_transition == p.end_transition &&
|
219
|
+
offset == p.offset
|
220
|
+
end
|
221
|
+
|
222
|
+
# Returns true if this TimezonePeriods is equal to p. This compares the
|
223
|
+
# start_transition, end_transition and offset using eql?
|
224
|
+
def eql?(p)
|
225
|
+
p.kind_of?(TimezonePeriod) &&
|
226
|
+
start_transition.eql?(p.start_transition) &&
|
227
|
+
end_transition.eql?(p.end_transition) &&
|
228
|
+
offset.eql?(p.offset)
|
229
|
+
end
|
230
|
+
|
231
|
+
# Returns a hash of this TimezonePeriod.
|
232
|
+
def hash
|
233
|
+
result = @start_transition.hash ^ @end_transition.hash
|
234
|
+
result ^= @offset.hash unless @start_transition || @end_transition
|
235
|
+
result
|
236
|
+
end
|
237
|
+
|
238
|
+
# Returns internal object state as a programmer-readable string.
|
239
|
+
def inspect
|
240
|
+
result = "#<#{self.class}: #{@start_transition.inspect},#{@end_transition.inspect}"
|
241
|
+
result << ",#{@offset.inspect}>" unless @start_transition || @end_transition
|
242
|
+
result + '>'
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|