tzinfo 1.2.10 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.yardopts +3 -0
  4. data/CHANGES.md +573 -391
  5. data/LICENSE +12 -12
  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 +181 -0
  16. data/lib/tzinfo/data_sources/ruby_data_source.rb +145 -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 +596 -0
  20. data/lib/tzinfo/data_sources/zoneinfo_reader.rb +486 -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/string_deduper.rb +118 -0
  42. data/lib/tzinfo/time_with_offset.rb +154 -0
  43. data/lib/tzinfo/timestamp.rb +552 -0
  44. data/lib/tzinfo/timestamp_with_offset.rb +85 -0
  45. data/lib/tzinfo/timezone.rb +989 -502
  46. data/lib/tzinfo/timezone_offset.rb +84 -74
  47. data/lib/tzinfo/timezone_period.rb +151 -217
  48. data/lib/tzinfo/timezone_proxy.rb +70 -79
  49. data/lib/tzinfo/timezone_transition.rb +77 -109
  50. data/lib/tzinfo/transition_rule.rb +207 -77
  51. data/lib/tzinfo/transitions_timezone_period.rb +63 -0
  52. data/lib/tzinfo/untaint_ext.rb +18 -0
  53. data/lib/tzinfo/version.rb +7 -0
  54. data/lib/tzinfo/with_offset.rb +61 -0
  55. data/lib/tzinfo.rb +82 -40
  56. data.tar.gz.sig +0 -0
  57. metadata +49 -104
  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_core_support.rb +0 -169
  67. data/lib/tzinfo/ruby_country_info.rb +0 -74
  68. data/lib/tzinfo/ruby_data_source.rb +0 -140
  69. data/lib/tzinfo/time_or_datetime.rb +0 -351
  70. data/lib/tzinfo/timezone_definition.rb +0 -36
  71. data/lib/tzinfo/timezone_index_definition.rb +0 -54
  72. data/lib/tzinfo/timezone_info.rb +0 -30
  73. data/lib/tzinfo/timezone_transition_definition.rb +0 -104
  74. data/lib/tzinfo/transition_data_timezone_info.rb +0 -274
  75. data/lib/tzinfo/zoneinfo_country_info.rb +0 -37
  76. data/lib/tzinfo/zoneinfo_data_source.rb +0 -512
  77. data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -520
  78. data/test/assets/payload.rb +0 -1
  79. data/test/tc_annual_rules.rb +0 -95
  80. data/test/tc_country.rb +0 -238
  81. data/test/tc_country_index_definition.rb +0 -69
  82. data/test/tc_country_info.rb +0 -16
  83. data/test/tc_country_timezone.rb +0 -173
  84. data/test/tc_data_source.rb +0 -218
  85. data/test/tc_data_timezone.rb +0 -99
  86. data/test/tc_data_timezone_info.rb +0 -18
  87. data/test/tc_info_timezone.rb +0 -34
  88. data/test/tc_linked_timezone.rb +0 -155
  89. data/test/tc_linked_timezone_info.rb +0 -23
  90. data/test/tc_offset_rationals.rb +0 -23
  91. data/test/tc_posix_time_zone_parser.rb +0 -261
  92. data/test/tc_ruby_core_support.rb +0 -168
  93. data/test/tc_ruby_country_info.rb +0 -110
  94. data/test/tc_ruby_data_source.rb +0 -173
  95. data/test/tc_time_or_datetime.rb +0 -674
  96. data/test/tc_timezone.rb +0 -1361
  97. data/test/tc_timezone_definition.rb +0 -113
  98. data/test/tc_timezone_index_definition.rb +0 -73
  99. data/test/tc_timezone_info.rb +0 -11
  100. data/test/tc_timezone_london.rb +0 -143
  101. data/test/tc_timezone_melbourne.rb +0 -142
  102. data/test/tc_timezone_new_york.rb +0 -142
  103. data/test/tc_timezone_offset.rb +0 -126
  104. data/test/tc_timezone_period.rb +0 -555
  105. data/test/tc_timezone_proxy.rb +0 -136
  106. data/test/tc_timezone_transition.rb +0 -366
  107. data/test/tc_timezone_transition_definition.rb +0 -295
  108. data/test/tc_timezone_utc.rb +0 -27
  109. data/test/tc_transition_data_timezone_info.rb +0 -433
  110. data/test/tc_transition_rule.rb +0 -663
  111. data/test/tc_zoneinfo_country_info.rb +0 -78
  112. data/test/tc_zoneinfo_data_source.rb +0 -1223
  113. data/test/tc_zoneinfo_timezone_info.rb +0 -2153
  114. data/test/test_utils.rb +0 -208
  115. data/test/ts_all.rb +0 -7
  116. data/test/ts_all_ruby.rb +0 -5
  117. data/test/ts_all_zoneinfo.rb +0 -9
  118. data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +0 -89
  119. data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +0 -327
  120. data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +0 -230
  121. data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +0 -19
  122. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +0 -21
  123. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +0 -21
  124. data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +0 -21
  125. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +0 -273
  126. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +0 -198
  127. data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +0 -333
  128. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +0 -277
  129. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +0 -235
  130. data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +0 -16
  131. data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +0 -940
  132. data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +0 -609
  133. data/test/tzinfo-data/tzinfo/data/version.rb +0 -20
  134. data/test/tzinfo-data/tzinfo/data.rb +0 -8
  135. data/test/zoneinfo/America/Argentina/Buenos_Aires +0 -0
  136. data/test/zoneinfo/America/New_York +0 -0
  137. data/test/zoneinfo/Australia/Melbourne +0 -0
  138. data/test/zoneinfo/EST +0 -0
  139. data/test/zoneinfo/Etc/UTC +0 -0
  140. data/test/zoneinfo/Europe/Amsterdam +0 -0
  141. data/test/zoneinfo/Europe/Andorra +0 -0
  142. data/test/zoneinfo/Europe/London +0 -0
  143. data/test/zoneinfo/Europe/Paris +0 -0
  144. data/test/zoneinfo/Europe/Prague +0 -0
  145. data/test/zoneinfo/Factory +0 -0
  146. data/test/zoneinfo/iso3166.tab +0 -274
  147. data/test/zoneinfo/leapseconds +0 -78
  148. data/test/zoneinfo/posix/Europe/London +0 -0
  149. data/test/zoneinfo/posixrules +0 -0
  150. data/test/zoneinfo/right/Europe/London +0 -0
  151. data/test/zoneinfo/zone.tab +0 -452
  152. data/test/zoneinfo/zone1970.tab +0 -384
  153. data/tzinfo.gemspec +0 -21
@@ -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