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,101 +1,111 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module TZInfo
|
2
|
-
# Represents an offset
|
5
|
+
# Represents an offset from UTC observed by a time zone.
|
3
6
|
class TimezoneOffset
|
4
|
-
#
|
5
|
-
# any adjustment made for daylight
|
6
|
-
# constant throughout the year.
|
7
|
+
# Returns the base offset from UTC in seconds (`observed_utc_offset -
|
8
|
+
# std_offset`). This does not include any adjustment made for daylight
|
9
|
+
# savings time and will typically remain constant throughout the year.
|
7
10
|
#
|
8
11
|
# To obtain the currently observed offset from UTC, including the effect of
|
9
|
-
# daylight savings time, use
|
12
|
+
# daylight savings time, use {observed_utc_offset} instead.
|
10
13
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
14
|
+
# If you require accurate {base_utc_offset} values, you should install the
|
15
|
+
# tzinfo-data gem and set {DataSources::RubyDataSource} as the {DataSource}.
|
16
|
+
# When using {DataSources::ZoneinfoDataSource}, the value of
|
17
|
+
# {base_utc_offset} has to be derived from changes to the observed UTC
|
18
|
+
# offset and DST status since it is not included in zoneinfo files.
|
15
19
|
#
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# hour) if daylight savings is
|
20
|
+
# @return [Integer] the base offset from UTC in seconds.
|
21
|
+
attr_reader :base_utc_offset
|
22
|
+
alias utc_offset base_utc_offset
|
23
|
+
|
24
|
+
# Returns the offset from the time zone's standard time in seconds
|
25
|
+
# (`observed_utc_offset - base_utc_offset`). Zero when daylight savings time
|
26
|
+
# is not in effect. Non-zero (usually 3600 = 1 hour) if daylight savings is
|
27
|
+
# being observed.
|
23
28
|
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
+
# If you require accurate {std_offset} values, you should install the
|
30
|
+
# tzinfo-data gem and set {DataSources::RubyDataSource} as the {DataSource}.
|
31
|
+
# When using {DataSources::ZoneinfoDataSource}, the value of {std_offset}
|
32
|
+
# has to be derived from changes to the observed UTC offset and DST status
|
33
|
+
# since it is not included in zoneinfo files.
|
29
34
|
#
|
30
|
-
#
|
31
|
-
#
|
35
|
+
# @return [Integer] the offset from the time zone's standard time in
|
36
|
+
# seconds.
|
32
37
|
attr_reader :std_offset
|
33
|
-
|
34
|
-
#
|
35
|
-
#
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
|
39
|
+
# Returns the observed offset from UTC in seconds (`base_utc_offset +
|
40
|
+
# std_offset`). This includes adjustments made for daylight savings time.
|
41
|
+
#
|
42
|
+
# @return [Integer] the observed offset from UTC in seconds.
|
43
|
+
attr_reader :observed_utc_offset
|
44
|
+
alias utc_total_offset observed_utc_offset
|
45
|
+
|
46
|
+
# The abbreviation that identifies this offset. For example GMT
|
47
|
+
# (Greenwich Mean Time) or BST (British Summer Time) for Europe/London.
|
48
|
+
#
|
49
|
+
# @return [String] the abbreviation that identifies this offset.
|
41
50
|
attr_reader :abbreviation
|
42
|
-
|
43
|
-
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
alias abbr abbreviation
|
52
|
+
|
53
|
+
# Initializes a new {TimezoneOffset}.
|
54
|
+
#
|
55
|
+
# {TimezoneOffset} instances should not normally be constructed manually.
|
56
|
+
#
|
57
|
+
# The passed in `abbreviation` instance will be frozen.
|
58
|
+
#
|
59
|
+
# @param base_utc_offset [Integer] the base offset from UTC in seconds.
|
60
|
+
# @param std_offset [Integer] the offset from standard time in seconds.
|
61
|
+
# @param abbreviation [String] the abbreviation identifying the offset.
|
62
|
+
def initialize(base_utc_offset, std_offset, abbreviation)
|
63
|
+
@base_utc_offset = base_utc_offset
|
64
|
+
@std_offset = std_offset
|
65
|
+
@abbreviation = abbreviation.freeze
|
66
|
+
|
67
|
+
@observed_utc_offset = @base_utc_offset + @std_offset
|
51
68
|
end
|
52
|
-
|
53
|
-
#
|
69
|
+
|
70
|
+
# Determines if daylight savings is in effect (i.e. if {std_offset} is
|
71
|
+
# non-zero).
|
72
|
+
#
|
73
|
+
# @return [Boolean] `true` if {std_offset} is non-zero, otherwise `false`.
|
54
74
|
def dst?
|
55
75
|
@std_offset != 0
|
56
76
|
end
|
57
|
-
|
58
|
-
#
|
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.
|
77
|
+
|
78
|
+
# Determines if this {TimezoneOffset} is equal to another instance.
|
70
79
|
#
|
71
|
-
#
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
+
# @param toi [Object] the instance to test for equality.
|
81
|
+
# @return [Boolean] `true` if `toi` is a {TimezoneOffset} with the same
|
82
|
+
# {utc_offset}, {std_offset} and {abbreviation} as this {TimezoneOffset},
|
83
|
+
# otherwise `false`.
|
80
84
|
def ==(toi)
|
81
85
|
toi.kind_of?(TimezoneOffset) &&
|
82
|
-
|
86
|
+
base_utc_offset == toi.base_utc_offset && std_offset == toi.std_offset && abbreviation == toi.abbreviation
|
83
87
|
end
|
84
|
-
|
85
|
-
#
|
86
|
-
#
|
88
|
+
|
89
|
+
# Determines if this {TimezoneOffset} is equal to another instance.
|
90
|
+
#
|
91
|
+
# @param toi [Object] the instance to test for equality.
|
92
|
+
# @return [Boolean] `true` if `toi` is a {TimezoneOffset} with the same
|
93
|
+
# {utc_offset}, {std_offset} and {abbreviation} as this {TimezoneOffset},
|
94
|
+
# otherwise `false`.
|
87
95
|
def eql?(toi)
|
88
96
|
self == toi
|
89
97
|
end
|
90
|
-
|
91
|
-
#
|
98
|
+
|
99
|
+
# @return [Integer] a hash based on {utc_offset}, {std_offset} and
|
100
|
+
# {abbreviation}.
|
92
101
|
def hash
|
93
|
-
|
102
|
+
[@base_utc_offset, @std_offset, @abbreviation].hash
|
94
103
|
end
|
95
|
-
|
96
|
-
#
|
104
|
+
|
105
|
+
# @return [String] the internal object state as a programmer-readable
|
106
|
+
# `String`.
|
97
107
|
def inspect
|
98
|
-
"#<#{self.class}:
|
108
|
+
"#<#{self.class}: @base_utc_offset=#{@base_utc_offset}, @std_offset=#{@std_offset}, @abbreviation=#{@abbreviation}>"
|
99
109
|
end
|
100
110
|
end
|
101
111
|
end
|
@@ -1,245 +1,179 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module TZInfo
|
2
|
-
#
|
5
|
+
# {TimezonePeriod} represents a period of time for a time zone where the same
|
6
|
+
# offset from UTC applies. It provides access to the observed offset, time
|
7
|
+
# zone abbreviation, start time and end time.
|
3
8
|
#
|
4
|
-
#
|
5
|
-
#
|
9
|
+
# The period of time can be unbounded at the start, end, or both the start
|
10
|
+
# and end.
|
11
|
+
#
|
12
|
+
# @abstract Time zone period data will returned as an instance of one of the
|
13
|
+
# subclasses of {TimezonePeriod}.
|
6
14
|
class TimezonePeriod
|
7
|
-
#
|
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.
|
15
|
+
# @return [TimezoneOffset] the offset that applies in the period of time.
|
16
16
|
attr_reader :offset
|
17
|
-
|
18
|
-
# Initializes a
|
19
|
-
#
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# constant throughout the year.
|
17
|
+
|
18
|
+
# Initializes a {TimezonePeriod}.
|
19
|
+
#
|
20
|
+
# @param offset [TimezoneOffset] the offset that is observed for the period
|
21
|
+
# of time.
|
22
|
+
# @raise [ArgumentError] if `offset` is `nil`.
|
23
|
+
def initialize(offset)
|
24
|
+
raise ArgumentError, 'offset must be specified' unless offset
|
25
|
+
@offset = offset
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [TimezoneTransition] the transition that defines the start of this
|
29
|
+
# {TimezonePeriod} (`nil` if the start is unbounded).
|
30
|
+
def start_transition
|
31
|
+
raise_not_implemented(:start_transition)
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [TimezoneTransition] the transition that defines the end of this
|
35
|
+
# {TimezonePeriod} (`nil` if the end is unbounded).
|
36
|
+
def end_transition
|
37
|
+
raise_not_implemented(:end_transition)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns the base offset from UTC in seconds (`observed_utc_offset -
|
41
|
+
# std_offset`). This does not include any adjustment made for daylight
|
42
|
+
# savings time and will typically remain constant throughout the year.
|
44
43
|
#
|
45
44
|
# To obtain the currently observed offset from UTC, including the effect of
|
46
|
-
# daylight savings time, use
|
45
|
+
# daylight savings time, use {observed_utc_offset} instead.
|
47
46
|
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
47
|
+
# If you require accurate {base_utc_offset} values, you should install the
|
48
|
+
# tzinfo-data gem and set {DataSources::RubyDataSource} as the {DataSource}.
|
49
|
+
# When using {DataSources::ZoneinfoDataSource}, the value of
|
50
|
+
# {base_utc_offset} has to be derived from changes to the observed UTC
|
51
|
+
# offset and DST status since it is not included in zoneinfo files.
|
52
52
|
#
|
53
|
-
#
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
#
|
60
|
-
#
|
61
|
-
# hour) if daylight savings is
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
53
|
+
# @return [Integer] the base offset from UTC in seconds.
|
54
|
+
def base_utc_offset
|
55
|
+
@offset.base_utc_offset
|
56
|
+
end
|
57
|
+
alias utc_offset base_utc_offset
|
58
|
+
|
59
|
+
# Returns the offset from the time zone's standard time in seconds
|
60
|
+
# (`observed_utc_offset - base_utc_offset`). Zero when daylight savings time
|
61
|
+
# is not in effect. Non-zero (usually 3600 = 1 hour) if daylight savings is
|
62
|
+
# being observed.
|
63
|
+
#
|
64
|
+
# If you require accurate {std_offset} values, you should install the
|
65
|
+
# tzinfo-data gem and set {DataSources::RubyDataSource} as the {DataSource}.
|
66
|
+
# When using {DataSources::ZoneinfoDataSource}, the value of {std_offset}
|
67
|
+
# has to be derived from changes to the observed UTC offset and DST status
|
68
|
+
# since it is not included in zoneinfo files.
|
69
|
+
#
|
70
|
+
# @return [Integer] the offset from the time zone's standard time in
|
71
|
+
# seconds.
|
71
72
|
def std_offset
|
72
73
|
@offset.std_offset
|
73
74
|
end
|
74
|
-
|
75
|
-
# The
|
76
|
-
# (British Summer Time) for
|
77
|
-
#
|
75
|
+
|
76
|
+
# The abbreviation that identifies this offset. For example GMT
|
77
|
+
# (Greenwich Mean Time) or BST (British Summer Time) for Europe/London.
|
78
|
+
#
|
79
|
+
# @return [String] the abbreviation that identifies this offset.
|
78
80
|
def abbreviation
|
79
81
|
@offset.abbreviation
|
80
82
|
end
|
81
|
-
alias
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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.
|
83
|
+
alias abbr abbreviation
|
84
|
+
alias zone_identifier abbreviation
|
85
|
+
|
86
|
+
# Returns the observed offset from UTC in seconds (`base_utc_offset +
|
87
|
+
# std_offset`). This includes adjustments made for daylight savings time.
|
88
|
+
#
|
89
|
+
# @return [Integer] the observed offset from UTC in seconds.
|
90
|
+
def observed_utc_offset
|
91
|
+
@offset.observed_utc_offset
|
92
|
+
end
|
93
|
+
alias utc_total_offset observed_utc_offset
|
94
|
+
|
95
|
+
# Determines if daylight savings is in effect (i.e. if {std_offset} is
|
96
|
+
# non-zero).
|
97
|
+
#
|
98
|
+
# @return [Boolean] `true` if {std_offset} is non-zero, otherwise `false`.
|
148
99
|
def dst?
|
149
100
|
@offset.dst?
|
150
101
|
end
|
151
|
-
|
152
|
-
#
|
102
|
+
|
103
|
+
# Returns the UTC start time of the period or `nil` if the start of the
|
104
|
+
# period is unbounded.
|
153
105
|
#
|
154
|
-
#
|
155
|
-
|
156
|
-
|
157
|
-
end
|
158
|
-
|
159
|
-
# true if the given UTC DateTime is after the start of the period
|
160
|
-
# (inclusive); otherwise false.
|
106
|
+
# The result is returned as a {Timestamp}. To obtain the start time as a
|
107
|
+
# `Time` or `DateTime`, call either {Timestamp#to_time to_time} or
|
108
|
+
# {Timestamp#to_datetime to_datetime} on the result.
|
161
109
|
#
|
162
|
-
#
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
#
|
110
|
+
# @return [Timestamp] the UTC start time of the period or `nil` if the start
|
111
|
+
# of the period is unbounded.
|
112
|
+
def starts_at
|
113
|
+
timestamp(start_transition)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Returns the UTC end time of the period or `nil` if the end of the period
|
117
|
+
# is unbounded.
|
169
118
|
#
|
170
|
-
#
|
171
|
-
|
172
|
-
|
173
|
-
end
|
174
|
-
|
175
|
-
# true if this period is valid for the given local DateTime; otherwise
|
176
|
-
# false.
|
119
|
+
# The result is returned as a {Timestamp}. To obtain the end time as a
|
120
|
+
# `Time` or `DateTime`, call either {Timestamp#to_time to_time} or
|
121
|
+
# {Timestamp#to_datetime to_datetime} on the result.
|
177
122
|
#
|
178
|
-
#
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
#
|
123
|
+
# @return [Timestamp] the UTC end time of the period or `nil` if the end of
|
124
|
+
# the period is unbounded.
|
125
|
+
def ends_at
|
126
|
+
timestamp(end_transition)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Returns the local start time of the period or `nil` if the start of the
|
130
|
+
# period is unbounded.
|
185
131
|
#
|
186
|
-
#
|
187
|
-
|
188
|
-
|
189
|
-
end
|
190
|
-
|
191
|
-
# true if the given local DateTime is before the end of the period
|
192
|
-
# (exclusive); otherwise false.
|
132
|
+
# The result is returned as a {TimestampWithOffset}. To obtain the start
|
133
|
+
# time as a `Time` or `DateTime`, call either {TimestampWithOffset#to_time
|
134
|
+
# to_time} or {TimestampWithOffset#to_datetime to_datetime} on the result.
|
193
135
|
#
|
194
|
-
#
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
136
|
+
# @return [TimestampWithOffset] the local start time of the period or `nil`
|
137
|
+
# if the start of the period is unbounded.
|
138
|
+
def local_starts_at
|
139
|
+
timestamp_with_offset(start_transition)
|
140
|
+
end
|
141
|
+
|
142
|
+
# Returns the local end time of the period or `nil` if the end of the period
|
143
|
+
# is unbounded.
|
200
144
|
#
|
201
|
-
#
|
202
|
-
|
203
|
-
|
204
|
-
end
|
205
|
-
|
206
|
-
# Converts a local DateTime to UTC based on the offset of this period.
|
145
|
+
# The result is returned as a {TimestampWithOffset}. To obtain the end time
|
146
|
+
# as a `Time` or `DateTime`, call either {TimestampWithOffset#to_time
|
147
|
+
# to_time} or {TimestampWithOffset#to_datetime to_datetime} on the result.
|
207
148
|
#
|
208
|
-
#
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
end
|
230
|
-
|
231
|
-
#
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
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 + '>'
|
149
|
+
# @return [TimestampWithOffset] the local end time of the period or `nil` if
|
150
|
+
# the end of the period is unbounded.
|
151
|
+
def local_ends_at
|
152
|
+
timestamp_with_offset(end_transition)
|
153
|
+
end
|
154
|
+
|
155
|
+
private
|
156
|
+
|
157
|
+
# Raises a {NotImplementedError} to indicate that subclasses should override
|
158
|
+
# a method.
|
159
|
+
#
|
160
|
+
# @raise [NotImplementedError] always.
|
161
|
+
def raise_not_implemented(method_name)
|
162
|
+
raise NotImplementedError, "Subclasses must override #{method_name}"
|
163
|
+
end
|
164
|
+
|
165
|
+
# @param transition [TimezoneTransition] a transition or `nil`.
|
166
|
+
# @return [Timestamp] the {Timestamp} representing when a transition occurs,
|
167
|
+
# or `nil` if `transition` is `nil`.
|
168
|
+
def timestamp(transition)
|
169
|
+
transition ? transition.at : nil
|
170
|
+
end
|
171
|
+
|
172
|
+
# @param transition [TimezoneTransition] a transition or `nil`.
|
173
|
+
# @return [TimestampWithOffset] a {Timestamp} representing when a transition
|
174
|
+
# occurs with offset set to {#offset}, or `nil` if `transition` is `nil`.
|
175
|
+
def timestamp_with_offset(transition)
|
176
|
+
transition ? TimestampWithOffset.set_timezone_offset(transition.at, offset) : nil
|
243
177
|
end
|
244
178
|
end
|
245
179
|
end
|