tzinfo 1.2.10 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.yardopts +3 -0
  4. data/CHANGES.md +583 -391
  5. data/LICENSE +13 -13
  6. data/README.md +368 -114
  7. data/lib/tzinfo/annual_rules.rb +32 -12
  8. data/lib/tzinfo/country.rb +141 -129
  9. data/lib/tzinfo/country_timezone.rb +70 -112
  10. data/lib/tzinfo/data_source.rb +400 -144
  11. data/lib/tzinfo/data_sources/constant_offset_data_timezone_info.rb +56 -0
  12. data/lib/tzinfo/data_sources/country_info.rb +42 -0
  13. data/lib/tzinfo/data_sources/data_timezone_info.rb +91 -0
  14. data/lib/tzinfo/data_sources/linked_timezone_info.rb +33 -0
  15. data/lib/tzinfo/data_sources/posix_time_zone_parser.rb +177 -0
  16. data/lib/tzinfo/data_sources/ruby_data_source.rb +141 -0
  17. data/lib/tzinfo/data_sources/timezone_info.rb +47 -0
  18. data/lib/tzinfo/data_sources/transitions_data_timezone_info.rb +214 -0
  19. data/lib/tzinfo/data_sources/zoneinfo_data_source.rb +592 -0
  20. data/lib/tzinfo/data_sources/zoneinfo_reader.rb +482 -0
  21. data/lib/tzinfo/data_sources.rb +8 -0
  22. data/lib/tzinfo/data_timezone.rb +33 -47
  23. data/lib/tzinfo/datetime_with_offset.rb +153 -0
  24. data/lib/tzinfo/format1/country_definer.rb +17 -0
  25. data/lib/tzinfo/format1/country_index_definition.rb +64 -0
  26. data/lib/tzinfo/format1/timezone_definer.rb +64 -0
  27. data/lib/tzinfo/format1/timezone_definition.rb +39 -0
  28. data/lib/tzinfo/format1/timezone_index_definition.rb +77 -0
  29. data/lib/tzinfo/format1.rb +10 -0
  30. data/lib/tzinfo/format2/country_definer.rb +68 -0
  31. data/lib/tzinfo/format2/country_index_definer.rb +68 -0
  32. data/lib/tzinfo/format2/country_index_definition.rb +46 -0
  33. data/lib/tzinfo/format2/timezone_definer.rb +94 -0
  34. data/lib/tzinfo/format2/timezone_definition.rb +73 -0
  35. data/lib/tzinfo/format2/timezone_index_definer.rb +45 -0
  36. data/lib/tzinfo/format2/timezone_index_definition.rb +55 -0
  37. data/lib/tzinfo/format2.rb +10 -0
  38. data/lib/tzinfo/info_timezone.rb +26 -21
  39. data/lib/tzinfo/linked_timezone.rb +33 -52
  40. data/lib/tzinfo/offset_timezone_period.rb +42 -0
  41. data/lib/tzinfo/ruby_core_support.rb +24 -155
  42. data/lib/tzinfo/string_deduper.rb +118 -0
  43. data/lib/tzinfo/time_with_offset.rb +154 -0
  44. data/lib/tzinfo/timestamp.rb +552 -0
  45. data/lib/tzinfo/timestamp_with_offset.rb +85 -0
  46. data/lib/tzinfo/timezone.rb +989 -502
  47. data/lib/tzinfo/timezone_offset.rb +84 -74
  48. data/lib/tzinfo/timezone_period.rb +151 -217
  49. data/lib/tzinfo/timezone_proxy.rb +70 -79
  50. data/lib/tzinfo/timezone_transition.rb +77 -109
  51. data/lib/tzinfo/transition_rule.rb +207 -77
  52. data/lib/tzinfo/transitions_timezone_period.rb +63 -0
  53. data/lib/tzinfo/version.rb +7 -0
  54. data/lib/tzinfo/with_offset.rb +61 -0
  55. data/lib/tzinfo.rb +78 -40
  56. data.tar.gz.sig +0 -0
  57. metadata +50 -105
  58. metadata.gz.sig +0 -0
  59. data/Rakefile +0 -107
  60. data/lib/tzinfo/country_index_definition.rb +0 -31
  61. data/lib/tzinfo/country_info.rb +0 -42
  62. data/lib/tzinfo/data_timezone_info.rb +0 -55
  63. data/lib/tzinfo/linked_timezone_info.rb +0 -26
  64. data/lib/tzinfo/offset_rationals.rb +0 -77
  65. data/lib/tzinfo/posix_time_zone_parser.rb +0 -136
  66. data/lib/tzinfo/ruby_country_info.rb +0 -74
  67. data/lib/tzinfo/ruby_data_source.rb +0 -140
  68. data/lib/tzinfo/time_or_datetime.rb +0 -351
  69. data/lib/tzinfo/timezone_definition.rb +0 -36
  70. data/lib/tzinfo/timezone_index_definition.rb +0 -54
  71. data/lib/tzinfo/timezone_info.rb +0 -30
  72. data/lib/tzinfo/timezone_transition_definition.rb +0 -104
  73. data/lib/tzinfo/transition_data_timezone_info.rb +0 -274
  74. data/lib/tzinfo/zoneinfo_country_info.rb +0 -37
  75. data/lib/tzinfo/zoneinfo_data_source.rb +0 -512
  76. data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -520
  77. data/test/assets/payload.rb +0 -1
  78. data/test/tc_annual_rules.rb +0 -95
  79. data/test/tc_country.rb +0 -238
  80. data/test/tc_country_index_definition.rb +0 -69
  81. data/test/tc_country_info.rb +0 -16
  82. data/test/tc_country_timezone.rb +0 -173
  83. data/test/tc_data_source.rb +0 -218
  84. data/test/tc_data_timezone.rb +0 -99
  85. data/test/tc_data_timezone_info.rb +0 -18
  86. data/test/tc_info_timezone.rb +0 -34
  87. data/test/tc_linked_timezone.rb +0 -155
  88. data/test/tc_linked_timezone_info.rb +0 -23
  89. data/test/tc_offset_rationals.rb +0 -23
  90. data/test/tc_posix_time_zone_parser.rb +0 -261
  91. data/test/tc_ruby_core_support.rb +0 -168
  92. data/test/tc_ruby_country_info.rb +0 -110
  93. data/test/tc_ruby_data_source.rb +0 -173
  94. data/test/tc_time_or_datetime.rb +0 -674
  95. data/test/tc_timezone.rb +0 -1361
  96. data/test/tc_timezone_definition.rb +0 -113
  97. data/test/tc_timezone_index_definition.rb +0 -73
  98. data/test/tc_timezone_info.rb +0 -11
  99. data/test/tc_timezone_london.rb +0 -143
  100. data/test/tc_timezone_melbourne.rb +0 -142
  101. data/test/tc_timezone_new_york.rb +0 -142
  102. data/test/tc_timezone_offset.rb +0 -126
  103. data/test/tc_timezone_period.rb +0 -555
  104. data/test/tc_timezone_proxy.rb +0 -136
  105. data/test/tc_timezone_transition.rb +0 -366
  106. data/test/tc_timezone_transition_definition.rb +0 -295
  107. data/test/tc_timezone_utc.rb +0 -27
  108. data/test/tc_transition_data_timezone_info.rb +0 -433
  109. data/test/tc_transition_rule.rb +0 -663
  110. data/test/tc_zoneinfo_country_info.rb +0 -78
  111. data/test/tc_zoneinfo_data_source.rb +0 -1223
  112. data/test/tc_zoneinfo_timezone_info.rb +0 -2153
  113. data/test/test_utils.rb +0 -208
  114. data/test/ts_all.rb +0 -7
  115. data/test/ts_all_ruby.rb +0 -5
  116. data/test/ts_all_zoneinfo.rb +0 -9
  117. data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +0 -89
  118. data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +0 -327
  119. data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +0 -230
  120. data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +0 -19
  121. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +0 -21
  122. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +0 -21
  123. data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +0 -21
  124. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +0 -273
  125. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +0 -198
  126. data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +0 -333
  127. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +0 -277
  128. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +0 -235
  129. data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +0 -16
  130. data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +0 -940
  131. data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +0 -609
  132. data/test/tzinfo-data/tzinfo/data/version.rb +0 -20
  133. data/test/tzinfo-data/tzinfo/data.rb +0 -8
  134. data/test/zoneinfo/America/Argentina/Buenos_Aires +0 -0
  135. data/test/zoneinfo/America/New_York +0 -0
  136. data/test/zoneinfo/Australia/Melbourne +0 -0
  137. data/test/zoneinfo/EST +0 -0
  138. data/test/zoneinfo/Etc/UTC +0 -0
  139. data/test/zoneinfo/Europe/Amsterdam +0 -0
  140. data/test/zoneinfo/Europe/Andorra +0 -0
  141. data/test/zoneinfo/Europe/London +0 -0
  142. data/test/zoneinfo/Europe/Paris +0 -0
  143. data/test/zoneinfo/Europe/Prague +0 -0
  144. data/test/zoneinfo/Factory +0 -0
  145. data/test/zoneinfo/iso3166.tab +0 -274
  146. data/test/zoneinfo/leapseconds +0 -78
  147. data/test/zoneinfo/posix/Europe/London +0 -0
  148. data/test/zoneinfo/posixrules +0 -0
  149. data/test/zoneinfo/right/Europe/London +0 -0
  150. data/test/zoneinfo/zone.tab +0 -452
  151. data/test/zoneinfo/zone1970.tab +0 -384
  152. data/tzinfo.gemspec +0 -21
@@ -0,0 +1,94 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ module TZInfo
5
+ module Format2
6
+ # Instances of {TimezoneDefiner} are yielded to TZInfo::Data modules by
7
+ # {TimezoneDefinition} to allow the offsets and transitions of the time zone
8
+ # to be specified.
9
+ #
10
+ # @private
11
+ class TimezoneDefiner #:nodoc:
12
+ # @return [Array<TimezoneTransition>] the defined transitions of the time
13
+ # zone.
14
+ attr_reader :transitions
15
+
16
+ # Initializes a new TimezoneDefiner.
17
+ #
18
+ # @param string_deduper [StringDeduper] a {StringDeduper} instance to use
19
+ # when deduping abbreviations.
20
+ def initialize(string_deduper)
21
+ @string_deduper = string_deduper
22
+ @offsets = {}
23
+ @transitions = []
24
+ end
25
+
26
+ # Returns the first offset to be defined or `nil` if no offsets have been
27
+ # defined. The first offset is observed before the time of the first
28
+ # transition.
29
+ #
30
+ # @return [TimezoneOffset] the first offset to be defined or `nil` if no
31
+ # offsets have been defined.
32
+ def first_offset
33
+ first = @offsets.first
34
+ first && first.last
35
+ end
36
+
37
+ # Defines an offset.
38
+ #
39
+ # @param id [Symbol] an arbitrary value used identify the offset in
40
+ # subsequent calls to transition. It must be unique.
41
+ # @param base_utc_offset [Integer] the base offset from UTC of the zone in
42
+ # seconds. This does not include daylight savings time.
43
+ # @param std_offset [Integer] the daylight savings offset from the base
44
+ # offset in seconds. Typically either 0 or 3600.
45
+ # @param abbreviation [String] an abbreviation for the offset, for
46
+ # example, EST or EDT.
47
+ # @raise [ArgumentError] if another offset has already been defined with
48
+ # the given id.
49
+ def offset(id, base_utc_offset, std_offset, abbreviation)
50
+ raise ArgumentError, 'An offset has already been defined with the given id' if @offsets.has_key?(id)
51
+
52
+ # Dedupe non-frozen literals from format 1 on all Ruby versions and
53
+ # format 2 on Ruby < 2.3 (without frozen_string_literal support).
54
+ abbreviation = @string_deduper.dedupe(abbreviation)
55
+
56
+ offset = TimezoneOffset.new(base_utc_offset, std_offset, abbreviation)
57
+ @offsets[id] = offset
58
+ @previous_offset ||= offset
59
+ end
60
+
61
+ # Defines a transition to a given offset.
62
+ #
63
+ # Transitions must be defined in increasing time order.
64
+ #
65
+ # @param offset_id [Symbol] references the id of a previously defined
66
+ # offset.
67
+ # @param timestamp_value [Integer] the time the transition occurs as a
68
+ # number of seconds since 1970-01-01 00:00:00 UTC ignoring leap seconds
69
+ # (i.e. each day is treated as if it were 86,400 seconds long).
70
+ # @raise [ArgumentError] if `offset_id` does not reference a defined
71
+ # offset.
72
+ # @raise [ArgumentError] if `timestamp_value` is not greater than the
73
+ # `timestamp_value` of the previously defined transition.
74
+ def transition(offset_id, timestamp_value)
75
+ offset = @offsets[offset_id]
76
+ raise ArgumentError, 'offset_id has not been defined' unless offset
77
+ raise ArgumentError, 'timestamp is not greater than the timestamp of the previously defined transition' if !@transitions.empty? && @transitions.last.timestamp_value >= timestamp_value
78
+ @transitions << TimezoneTransition.new(offset, @previous_offset, timestamp_value)
79
+ @previous_offset = offset
80
+ end
81
+
82
+ # Defines the rules that will be used for handling instants after the last
83
+ # transition.
84
+ #
85
+ # This method is currently just a placeholder for forward compatibility
86
+ # that accepts and ignores any arguments passed.
87
+ #
88
+ # Support for subsequent rules will be added in a future version of TZInfo
89
+ # and the rules will be included in format 2 releases of TZInfo::Data.
90
+ def subsequent_rules(*args)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,73 @@
1
+ # encoding: UTF-8
2
+
3
+ module TZInfo
4
+ module Format2
5
+ # {Format2::TimezoneDefinition} is included into format 2 time zone
6
+ # definition modules and provides methods for defining time zones.
7
+ #
8
+ # @private
9
+ module TimezoneDefinition #:nodoc:
10
+ # Adds class methods to the includee.
11
+ #
12
+ # @param base [Module] the includee.
13
+ def self.append_features(base)
14
+ super
15
+ base.extend(ClassMethods)
16
+ end
17
+
18
+ # Class methods for inclusion.
19
+ #
20
+ # @private
21
+ module ClassMethods #:nodoc:
22
+ # @return [TimezoneInfo] the last time zone to be defined.
23
+ def get
24
+ @timezone
25
+ end
26
+
27
+ private
28
+
29
+ # @return [Class] the class to be instantiated and yielded by
30
+ # {#timezone}.
31
+ def timezone_definer_class
32
+ TimezoneDefiner
33
+ end
34
+
35
+ # Defines a data time zone.
36
+ #
37
+ # @param identifier [String] the identifier of the time zone.
38
+ # @yield [definer] yields to the caller to define the time zone.
39
+ # @yieldparam definer [Object] an instance of the class returned by
40
+ # {#timezone_definer_class}, typically {TimezoneDefiner}.
41
+ def timezone(identifier)
42
+ # Dedupe non-frozen literals from format 1 on all Ruby versions and
43
+ # format 2 on Ruby < 2.3 (without frozen_string_literal support).
44
+ string_deduper = StringDeduper.global
45
+ identifier = string_deduper.dedupe(identifier)
46
+
47
+ definer = timezone_definer_class.new(string_deduper)
48
+ yield definer
49
+ transitions = definer.transitions
50
+
51
+ @timezone = if transitions.empty?
52
+ DataSources::ConstantOffsetDataTimezoneInfo.new(identifier, definer.first_offset)
53
+ else
54
+ DataSources::TransitionsDataTimezoneInfo.new(identifier, transitions)
55
+ end
56
+ end
57
+
58
+ # Defines a linked time zone.
59
+ #
60
+ # @param identifier [String] the identifier of the time zone being
61
+ # defined.
62
+ # @param link_to_identifier [String] the identifier the new time zone
63
+ # links to (is an alias for).
64
+ def linked_timezone(identifier, link_to_identifier)
65
+ # Dedupe non-frozen literals from format 1 on all Ruby versions and
66
+ # format 2 on Ruby < 2.3 (without frozen_string_literal support).
67
+ string_deduper = StringDeduper.global
68
+ @timezone = DataSources::LinkedTimezoneInfo.new(string_deduper.dedupe(identifier), string_deduper.dedupe(link_to_identifier))
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: UTF-8
2
+
3
+ module TZInfo
4
+ module Format2
5
+ # Instances of {TimezoneIndexDefiner} are yielded by
6
+ # {TimezoneIndexDefinition} to allow the time zone index to be defined.
7
+ #
8
+ # @private
9
+ class TimezoneIndexDefiner #:nodoc:
10
+ # @return [Array<String>] the identifiers of all data time zones.
11
+ attr_reader :data_timezones
12
+
13
+ # @return [Array<String>] the identifiers of all linked time zones.
14
+ attr_reader :linked_timezones
15
+
16
+ # Initializes a new TimezoneDefiner.
17
+ #
18
+ # @param string_deduper [StringDeduper] a {StringDeduper} instance to use
19
+ # when deduping identifiers.
20
+ def initialize(string_deduper)
21
+ @string_deduper = string_deduper
22
+ @data_timezones = []
23
+ @linked_timezones = []
24
+ end
25
+
26
+ # Adds a data time zone to the index.
27
+ #
28
+ # @param identifier [String] the time zone identifier.
29
+ def data_timezone(identifier)
30
+ # Dedupe non-frozen literals from format 1 on all Ruby versions and
31
+ # format 2 on Ruby < 2.3 (without frozen_string_literal support).
32
+ @data_timezones << @string_deduper.dedupe(identifier)
33
+ end
34
+
35
+ # Adds a linked time zone to the index.
36
+ #
37
+ # @param identifier [String] the time zone identifier.
38
+ def linked_timezone(identifier)
39
+ # Dedupe non-frozen literals from format 1 on all Ruby versions and
40
+ # format 2 on Ruby < 2.3 (without frozen_string_literal support).
41
+ @linked_timezones << @string_deduper.dedupe(identifier)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: UTF-8
2
+
3
+ module TZInfo
4
+ module Format2
5
+ # The format 2 time zone index file includes {TimezoneIndexDefinition},
6
+ # which provides the {TimezoneIndexDefinition::ClassMethods#timezone_index
7
+ # timezone_index} method used to define the index.
8
+ #
9
+ # @private
10
+ module TimezoneIndexDefinition #:nodoc:
11
+ # Adds class methods to the includee and initializes class instance
12
+ # variables.
13
+ #
14
+ # @param base [Module] the includee.
15
+ def self.append_features(base)
16
+ super
17
+ base.extend(ClassMethods)
18
+ base.instance_eval do
19
+ empty = [].freeze
20
+ @timezones = empty
21
+ @data_timezones = empty
22
+ @linked_timezones = empty
23
+ end
24
+ end
25
+
26
+ # Class methods for inclusion.
27
+ #
28
+ # @private
29
+ module ClassMethods #:nodoc:
30
+ # @return [Array<String>] a frozen `Array` containing the identifiers of
31
+ # all data time zones. Identifiers are sorted according to
32
+ # `String#<=>`.
33
+ attr_reader :data_timezones
34
+
35
+ # @return [Array<String>] a frozen `Array` containing the identifiers of
36
+ # all linked time zones. Identifiers are sorted according to
37
+ # `String#<=>`.
38
+ attr_reader :linked_timezones
39
+
40
+ # Defines the index.
41
+ #
42
+ # @yield [definer] yields to the caller to allow the index to be
43
+ # defined.
44
+ # @yieldparam definer [TimezoneIndexDefiner] a {TimezoneIndexDefiner}
45
+ # instance that should be used to define the index.
46
+ def timezone_index
47
+ definer = TimezoneIndexDefiner.new(StringDeduper.global)
48
+ yield definer
49
+ @data_timezones = definer.data_timezones.sort!.freeze
50
+ @linked_timezones = definer.linked_timezones.sort!.freeze
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: UTF-8
2
+
3
+ module TZInfo
4
+ # Modules and classes used by the format 2 version of TZInfo::Data.
5
+ #
6
+ # @private
7
+ module Format2 #:nodoc:
8
+ end
9
+ private_constant :Format2
10
+ end
@@ -1,30 +1,35 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TZInfo
2
4
 
3
- # A Timezone based on a TimezoneInfo.
5
+ # A {Timezone} based on a {DataSources::TimezoneInfo}.
4
6
  #
5
- # @private
6
- class InfoTimezone < Timezone #:nodoc:
7
-
8
- # Constructs a new InfoTimezone with a TimezoneInfo instance.
9
- def self.new(info)
10
- tz = super()
11
- tz.send(:setup, info)
12
- tz
7
+ # @abstract
8
+ class InfoTimezone < Timezone
9
+ # Initializes a new {InfoTimezone}.
10
+ #
11
+ # {InfoTimezone} instances should not normally be created directly. Use
12
+ # the {Timezone.get} method to obtain {Timezone} instances.
13
+ #
14
+ # @param info [DataSources::TimezoneInfo] a {DataSources::TimezoneInfo}
15
+ # instance supplied by a {DataSource} that will be used as the source of
16
+ # data for this {InfoTimezone}.
17
+ def initialize(info)
18
+ super()
19
+ @info = info
13
20
  end
14
-
15
- # The identifier of the timezone, e.g. "Europe/Paris".
21
+
22
+ # (see Timezone#identifier)
16
23
  def identifier
17
24
  @info.identifier
18
25
  end
19
-
26
+
20
27
  protected
21
- # The TimezoneInfo for this Timezone.
22
- def info
23
- @info
24
- end
25
-
26
- def setup(info)
27
- @info = info
28
- end
29
- end
28
+
29
+ # @return [DataSources::TimezoneInfo] the {DataSources::TimezoneInfo} this
30
+ # {InfoTimezone} is based on.
31
+ def info
32
+ @info
33
+ end
34
+ end
30
35
  end
@@ -1,63 +1,44 @@
1
+ # encoding: UTF-8
2
+
1
3
  module TZInfo
4
+ # Represents time zones that are defined as a link to or alias for another
5
+ # time zone.
6
+ class LinkedTimezone < InfoTimezone
7
+ # Initializes a new {LinkedTimezone}.
8
+ #
9
+ # {LinkedTimezone} instances should not normally be created directly. Use
10
+ # the {Timezone.get} method to obtain {Timezone} instances.
11
+ #
12
+ # @param info [DataSources::LinkedTimezoneInfo] a
13
+ # {DataSources::LinkedTimezoneInfo} instance supplied by a {DataSource}
14
+ # that will be used as the source of data for this {LinkedTimezone}.
15
+ def initialize(info)
16
+ super
17
+ @linked_timezone = Timezone.get(info.link_to_identifier)
18
+ end
2
19
 
3
- # A Timezone based on a LinkedTimezoneInfo.
4
- #
5
- # @private
6
- class LinkedTimezone < InfoTimezone #:nodoc:
7
- # Returns the TimezonePeriod for the given UTC time. utc can either be
8
- # a DateTime, Time or integer timestamp (Time.to_i). Any timezone
9
- # information in utc is ignored (it is treated as a UTC time).
10
- #
11
- # If no TimezonePeriod could be found, PeriodNotFound is raised.
12
- def period_for_utc(utc)
13
- @linked_timezone.period_for_utc(utc)
20
+ # (see Timezone#period_for)
21
+ def period_for(time)
22
+ @linked_timezone.period_for(time)
14
23
  end
15
-
16
- # Returns the set of TimezonePeriod instances that are valid for the given
17
- # local time as an array. If you just want a single period, use
18
- # period_for_local instead and specify how abiguities should be resolved.
19
- # Raises PeriodNotFound if no periods are found for the given time.
20
- def periods_for_local(local)
21
- @linked_timezone.periods_for_local(local)
24
+
25
+ # (see Timezone#periods_for_local)
26
+ def periods_for_local(local_time)
27
+ @linked_timezone.periods_for_local(local_time)
22
28
  end
23
-
24
- # Returns an Array of TimezoneTransition instances representing the times
25
- # where the UTC offset of the timezone changes.
26
- #
27
- # Transitions are returned up to a given date and time up to a given date
28
- # and time, specified in UTC (utc_to).
29
- #
30
- # A from date and time may also be supplied using the utc_from parameter
31
- # (also specified in UTC). If utc_from is not nil, only transitions from
32
- # that date and time onwards will be returned.
33
- #
34
- # Comparisons with utc_to are exclusive. Comparisons with utc_from are
35
- # inclusive. If a transition falls precisely on utc_to, it will be excluded.
36
- # If a transition falls on utc_from, it will be included.
37
- #
38
- # Transitions returned are ordered by when they occur, from earliest to
39
- # latest.
40
- #
41
- # utc_to and utc_from can be specified using either DateTime, Time or
42
- # integer timestamps (Time.to_i).
43
- #
44
- # If utc_from is specified and utc_to is not greater than utc_from, then
45
- # transitions_up_to raises an ArgumentError exception.
46
- def transitions_up_to(utc_to, utc_from = nil)
47
- @linked_timezone.transitions_up_to(utc_to, utc_from)
29
+
30
+ # (see Timezone#transitions_up_to)
31
+ def transitions_up_to(to, from = nil)
32
+ @linked_timezone.transitions_up_to(to, from)
48
33
  end
49
-
50
- # Returns the canonical zone for this Timezone.
34
+
35
+ # Returns the canonical {Timezone} instance for this {LinkedTimezone}.
36
+ #
37
+ # For a {LinkedTimezone}, this is the canonical zone of the link target.
51
38
  #
52
- # For a LinkedTimezone, this is the canonical zone of the link target.
39
+ # @return [Timezone] the canonical {Timezone} instance for this {Timezone}.
53
40
  def canonical_zone
54
41
  @linked_timezone.canonical_zone
55
42
  end
56
-
57
- protected
58
- def setup(info)
59
- super(info)
60
- @linked_timezone = Timezone.get(info.link_to_identifier)
61
- end
62
43
  end
63
44
  end
@@ -0,0 +1,42 @@
1
+ # encoding: UTF-8
2
+
3
+ module TZInfo
4
+ # Represents the infinite period of time in a time zone that constantly
5
+ # observes the same offset from UTC (has an unbounded start and end).
6
+ class OffsetTimezonePeriod < TimezonePeriod
7
+ # Initializes an {OffsetTimezonePeriod}.
8
+ #
9
+ # @param offset [TimezoneOffset] the offset that is constantly observed.
10
+ # @raise [ArgumentError] if `offset` is `nil`.
11
+ def initialize(offset)
12
+ super
13
+ end
14
+
15
+ # @return [TimezoneTransition] the transition that defines the start of this
16
+ # {TimezonePeriod}, always `nil` for {OffsetTimezonePeriod}.
17
+ def start_transition
18
+ nil
19
+ end
20
+
21
+ # @return [TimezoneTransition] the transition that defines the end of this
22
+ # {TimezonePeriod}, always `nil` for {OffsetTimezonePeriod}.
23
+ def end_transition
24
+ nil
25
+ end
26
+
27
+ # Determines if this {OffsetTimezonePeriod} is equal to another instance.
28
+ #
29
+ # @param p [Object] the instance to test for equality.
30
+ # @return [Boolean] `true` if `p` is a {OffsetTimezonePeriod} with the same
31
+ # {offset}, otherwise `false`.
32
+ def ==(p)
33
+ p.kind_of?(OffsetTimezonePeriod) && offset == p.offset
34
+ end
35
+ alias eql? ==
36
+
37
+ # @return [Integer] a hash based on {offset}.
38
+ def hash
39
+ offset.hash
40
+ end
41
+ end
42
+ end
@@ -1,169 +1,38 @@
1
- require 'date'
2
- require 'rational' unless defined?(Rational)
3
-
4
1
  module TZInfo
5
-
2
+
6
3
  # Methods to support different versions of Ruby.
7
4
  #
8
5
  # @private
9
6
  module RubyCoreSupport #:nodoc:
10
-
11
- # Use Rational.new! for performance reasons in Ruby 1.8.
12
- # This has been removed from 1.9, but Rational performs better.
13
- if Rational.respond_to? :new!
14
- def self.rational_new!(numerator, denominator = 1)
15
- Rational.new!(numerator, denominator)
16
- end
17
- else
18
- def self.rational_new!(numerator, denominator = 1)
19
- Rational(numerator, denominator)
20
- end
21
- end
22
-
23
- # Ruby 1.8.6 introduced new! and deprecated new0.
24
- # Ruby 1.9.0 removed new0.
25
- # Ruby trunk revision 31668 removed the new! method.
26
- # Still support new0 for better performance on older versions of Ruby (new0 indicates
27
- # that the rational has already been reduced to its lowest terms).
28
- # Fallback to jd with conversion from ajd if new! and new0 are unavailable.
29
- if DateTime.respond_to? :new!
30
- def self.datetime_new!(ajd = 0, of = 0, sg = Date::ITALY)
31
- DateTime.new!(ajd, of, sg)
32
- end
33
- elsif DateTime.respond_to? :new0
34
- def self.datetime_new!(ajd = 0, of = 0, sg = Date::ITALY)
35
- DateTime.new0(ajd, of, sg)
36
- end
37
- else
38
- HALF_DAYS_IN_DAY = rational_new!(1, 2)
7
+ class << self
8
+ # Object#untaint is deprecated and becomes a no-op in Ruby >= 2.7. It has
9
+ # been removed from Ruby 3.2.
10
+ if !Object.new.respond_to?(:untaint) || RUBY_VERSION =~ /\A(\d+)\.(\d+)(?:\.|\z)/ && ($1 == '2' && $2.to_i >= 7 || $1.to_i >= 3)
11
+ # :nocov_functional_untaint:
39
12
 
40
- def self.datetime_new!(ajd = 0, of = 0, sg = Date::ITALY)
41
- # Convert from an Astronomical Julian Day number to a civil Julian Day number.
42
- jd = ajd + of + HALF_DAYS_IN_DAY
43
-
44
- # Ruby trunk revision 31862 changed the behaviour of DateTime.jd so that it will no
45
- # longer accept a fractional civil Julian Day number if further arguments are specified.
46
- # Calculate the hours, minutes and seconds to pass to jd.
47
-
48
- jd_i = jd.to_i
49
- jd_i -= 1 if jd < 0
50
- hours = (jd - jd_i) * 24
51
- hours_i = hours.to_i
52
- minutes = (hours - hours_i) * 60
53
- minutes_i = minutes.to_i
54
- seconds = (minutes - minutes_i) * 60
55
-
56
- DateTime.jd(jd_i, hours_i, minutes_i, seconds, of, sg)
57
- end
58
- end
59
-
60
- # DateTime in Ruby 1.8.6 doesn't consider times within the 60th second to be
61
- # valid. When attempting to specify such a DateTime, subtract the fractional
62
- # part and then add it back later
63
- if Date.respond_to?(:valid_time?) && !Date.valid_time?(0, 0, rational_new!(59001, 1000)) # 0:0:59.001
64
- def self.datetime_new(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=Date::ITALY)
65
- if !s.kind_of?(Integer) && s > 59
66
- dt = DateTime.new(y, m, d, h, min, 59, of, sg)
67
- dt + (s - 59) / 86400
68
- else
69
- DateTime.new(y, m, d, h, min, s, of, sg)
13
+ # Returns the supplied `Object`
14
+ #
15
+ # @param o [Object] the `Object` to untaint.
16
+ # @return [Object] `o`.
17
+ def untaint(o)
18
+ o
70
19
  end
71
- end
72
- else
73
- def self.datetime_new(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=Date::ITALY)
74
- DateTime.new(y, m, d, h, min, s, of, sg)
75
- end
76
- end
77
-
78
- # Returns true if Time on the runtime platform supports Times defined
79
- # by negative 32-bit timestamps, otherwise false.
80
- begin
81
- Time.at(-1)
82
- Time.at(-2147483648)
83
-
84
- def self.time_supports_negative
85
- true
86
- end
87
- rescue ArgumentError
88
- def self.time_supports_negative
89
- false
90
- end
91
- end
92
-
93
- # Returns true if Time on the runtime platform supports Times defined by
94
- # 64-bit timestamps, otherwise false.
95
- begin
96
- Time.at(-2147483649)
97
- Time.at(2147483648)
98
-
99
- def self.time_supports_64bit
100
- true
101
- end
102
- rescue RangeError
103
- def self.time_supports_64bit
104
- false
105
- end
106
- end
107
-
108
- # Return the result of Time#nsec if it exists, otherwise return the
109
- # result of Time#usec * 1000.
110
- if Time.method_defined?(:nsec)
111
- def self.time_nsec(time)
112
- time.nsec
113
- end
114
- else
115
- def self.time_nsec(time)
116
- time.usec * 1000
117
- end
118
- end
119
-
120
- # Call String#force_encoding if this version of Ruby has encoding support
121
- # otherwise treat as a no-op.
122
- if String.method_defined?(:force_encoding)
123
- def self.force_encoding(str, encoding)
124
- str.force_encoding(encoding)
125
- end
126
- else
127
- def self.force_encoding(str, encoding)
128
- str
129
- end
130
- end
131
-
132
-
133
- # Wrapper for File.open that supports passing hash options for specifying
134
- # encodings on Ruby 1.9+. The options are ignored on earlier versions of
135
- # Ruby.
136
- if RUBY_VERSION =~ /\A1\.[0-8]\./
137
- def self.open_file(file_name, mode, opts, &block)
138
- File.open(file_name, mode, &block)
139
- end
140
- elsif RUBY_VERSION =~ /\A1\.9\./
141
- def self.open_file(file_name, mode, opts, &block)
142
- File.open(file_name, mode, opts, &block)
143
- end
144
- else
145
- # Evaluate method as a string because **opts isn't valid syntax prior to
146
- # Ruby 2.0.
147
- eval(<<-EOF
148
- def self.open_file(file_name, mode, opts, &block)
149
- File.open(file_name, mode, **opts, &block)
150
- end
151
- EOF
152
- )
153
- end
154
20
 
21
+ # :nocov_functional_untaint:
22
+ else
23
+ # :nocov_no_functional_untaint:
155
24
 
156
- # Object#untaint is a deprecated no-op in Ruby >= 2.7 and will be removed in
157
- # 3.2. Add a refinement to either silence the warning, or supply the method
158
- # if needed.
159
- if !Object.new.respond_to?(:untaint) || RUBY_VERSION =~ /\A(\d+)\.(\d+)(?:\.|\z)/ && ($1 == '2' && $2.to_i >= 7 || $1.to_i >= 3)
160
- module UntaintExt
161
- refine Object do
162
- def untaint
163
- self
164
- end
25
+ # Untaints and returns the supplied `Object`.
26
+ #
27
+ # @param o [Object] the `Object` to untaint.
28
+ # @return [Object] `o`.
29
+ def untaint(o)
30
+ o.untaint
165
31
  end
32
+
33
+ # :nocov_no_functional_untaint:
166
34
  end
167
35
  end
168
36
  end
37
+ private_constant :RubyCoreSupport
169
38
  end