activesupport 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activesupport might be problematic. Click here for more details.
- data/CHANGELOG +13 -1
- data/lib/active_support.rb +6 -0
- data/lib/active_support/cache.rb +3 -1
- data/lib/active_support/cache/compressed_mem_cache_store.rb +4 -4
- data/lib/active_support/core_ext/date/behavior.rb +26 -0
- data/lib/active_support/core_ext/date/calculations.rb +1 -1
- data/lib/active_support/core_ext/hash/except.rb +4 -3
- data/lib/active_support/core_ext/hash/slice.rb +3 -1
- data/lib/active_support/core_ext/module.rb +5 -0
- data/lib/active_support/core_ext/module/model_naming.rb +22 -0
- data/lib/active_support/core_ext/object/extending.rb +9 -8
- data/lib/active_support/core_ext/range/blockless_step.rb +2 -2
- data/lib/active_support/core_ext/rexml.rb +35 -0
- data/lib/active_support/core_ext/string/unicode.rb +11 -13
- data/lib/active_support/core_ext/time.rb +22 -1
- data/lib/active_support/dependencies.rb +393 -392
- data/lib/active_support/deprecation.rb +27 -9
- data/lib/active_support/inflections.rb +51 -49
- data/lib/active_support/inflector.rb +267 -262
- data/lib/active_support/json/encoders/date_time.rb +1 -1
- data/lib/active_support/ordered_options.rb +14 -12
- data/lib/active_support/string_inquirer.rb +11 -0
- data/lib/active_support/time_with_zone.rb +34 -13
- data/lib/active_support/values/time_zone.rb +348 -346
- data/lib/active_support/vendor.rb +2 -2
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/data_timezone.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/data_timezone_info.rb +2 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Africa/Algiers.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Africa/Cairo.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Africa/Casablanca.rb +2 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Africa/Harare.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Africa/Johannesburg.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Africa/Monrovia.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Africa/Nairobi.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Argentina/San_Juan.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Bogota.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Caracas.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Chicago.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Chihuahua.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Denver.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Godthab.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Guatemala.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Halifax.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Indiana/Indianapolis.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Juneau.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/La_Paz.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Lima.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Los_Angeles.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Mazatlan.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Mexico_City.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Monterrey.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/New_York.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Phoenix.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Regina.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Santiago.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/St_Johns.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/America/Tijuana.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Almaty.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Baghdad.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Baku.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Bangkok.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Chongqing.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Dhaka.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Hong_Kong.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Irkutsk.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Jakarta.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Jerusalem.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Kabul.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Kamchatka.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Karachi.rb +2 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Katmandu.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Kolkata.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Krasnoyarsk.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Kuala_Lumpur.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Kuwait.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Magadan.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Muscat.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Novosibirsk.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Rangoon.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Riyadh.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Seoul.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Shanghai.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Singapore.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Taipei.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Tashkent.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Tbilisi.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Tehran.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Tokyo.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Ulaanbaatar.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Urumqi.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Vladivostok.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Yakutsk.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Yekaterinburg.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Asia/Yerevan.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Atlantic/Azores.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Atlantic/Cape_Verde.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Atlantic/South_Georgia.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Australia/Adelaide.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Australia/Brisbane.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Australia/Darwin.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Australia/Hobart.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Australia/Melbourne.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Australia/Perth.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Australia/Sydney.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Etc/UTC.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Amsterdam.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Athens.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Belgrade.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Berlin.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Bratislava.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Brussels.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Bucharest.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Budapest.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Copenhagen.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Dublin.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Helsinki.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Istanbul.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Kiev.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Lisbon.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Ljubljana.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/London.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Madrid.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Minsk.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Moscow.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Paris.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Prague.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Riga.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Rome.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Sarajevo.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Skopje.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Sofia.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Stockholm.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Tallinn.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Vienna.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Vilnius.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Warsaw.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Europe/Zagreb.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Auckland.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Fiji.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Guam.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Honolulu.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Majuro.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Midway.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Noumea.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Pago_Pago.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Port_Moresby.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/definitions/Pacific/Tongatapu.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/info_timezone.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/linked_timezone.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/linked_timezone_info.rb +0 -0
- data/lib/active_support/vendor/tzinfo-0.3.9/tzinfo/offset_rationals.rb +95 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/time_or_datetime.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/timezone.rb +6 -6
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/timezone_definition.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/timezone_info.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/timezone_offset_info.rb +4 -4
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/timezone_period.rb +0 -0
- data/lib/active_support/vendor/{tzinfo-0.3.8 → tzinfo-0.3.9}/tzinfo/timezone_transition_info.rb +2 -2
- data/lib/active_support/version.rb +1 -1
- metadata +154 -151
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/offset_rationals.rb +0 -95
@@ -1,17 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module ActiveSupport #:nodoc:
|
2
|
+
class OrderedOptions < OrderedHash #:nodoc:
|
3
|
+
def []=(key, value)
|
4
|
+
super(key.to_sym, value)
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
def [](key)
|
8
|
+
super(key.to_sym)
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def method_missing(name, *args)
|
12
|
+
if name.to_s =~ /(.*)=$/
|
13
|
+
self[$1.to_sym] = args.first
|
14
|
+
else
|
15
|
+
self[name]
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -159,19 +159,24 @@ module ActiveSupport
|
|
159
159
|
utc == other
|
160
160
|
end
|
161
161
|
|
162
|
-
# If wrapped +time+ is a DateTime, use DateTime#since instead of <tt>+</tt>.
|
163
|
-
# Otherwise, just pass on to +method_missing+.
|
164
162
|
def +(other)
|
165
|
-
|
166
|
-
|
163
|
+
# If we're adding a Duration of variable length (i.e., years, months, days), move forward from #time,
|
164
|
+
# otherwise move forward from #utc, for accuracy when moving across DST boundaries
|
165
|
+
if duration_of_variable_length?(other)
|
166
|
+
method_missing(:+, other)
|
167
|
+
else
|
168
|
+
result = utc.acts_like?(:date) ? utc.since(other) : utc + other rescue utc.since(other)
|
169
|
+
result.in_time_zone(time_zone)
|
170
|
+
end
|
167
171
|
end
|
168
|
-
|
169
|
-
# If a time-like object is passed in, compare it with +utc+.
|
170
|
-
# Else if wrapped +time+ is a DateTime, use DateTime#ago instead of DateTime#-.
|
171
|
-
# Otherwise, just pass on to +method_missing+.
|
172
|
+
|
172
173
|
def -(other)
|
174
|
+
# If we're subtracting a Duration of variable length (i.e., years, months, days), move backwards from #time,
|
175
|
+
# otherwise move backwards #utc, for accuracy when moving across DST boundaries
|
173
176
|
if other.acts_like?(:time)
|
174
177
|
utc - other
|
178
|
+
elsif duration_of_variable_length?(other)
|
179
|
+
method_missing(:-, other)
|
175
180
|
else
|
176
181
|
result = utc.acts_like?(:date) ? utc.ago(other) : utc - other rescue utc.ago(other)
|
177
182
|
result.in_time_zone(time_zone)
|
@@ -179,15 +184,27 @@ module ActiveSupport
|
|
179
184
|
end
|
180
185
|
|
181
186
|
def since(other)
|
182
|
-
|
187
|
+
# If we're adding a Duration of variable length (i.e., years, months, days), move forward from #time,
|
188
|
+
# otherwise move forward from #utc, for accuracy when moving across DST boundaries
|
189
|
+
if duration_of_variable_length?(other)
|
190
|
+
method_missing(:since, other)
|
191
|
+
else
|
192
|
+
utc.since(other).in_time_zone(time_zone)
|
193
|
+
end
|
183
194
|
end
|
184
195
|
|
185
196
|
def ago(other)
|
186
|
-
|
197
|
+
since(-other)
|
187
198
|
end
|
188
|
-
|
199
|
+
|
189
200
|
def advance(options)
|
190
|
-
|
201
|
+
# If we're advancing a value of variable length (i.e., years, weeks, months, days), advance from #time,
|
202
|
+
# otherwise advance from #utc, for accuracy when moving across DST boundaries
|
203
|
+
if options.detect {|k,v| [:years, :weeks, :months, :days].include? k}
|
204
|
+
method_missing(:advance, options)
|
205
|
+
else
|
206
|
+
utc.advance(options).in_time_zone(time_zone)
|
207
|
+
end
|
191
208
|
end
|
192
209
|
|
193
210
|
%w(year mon month day mday hour min sec).each do |method_name|
|
@@ -246,7 +263,7 @@ module ActiveSupport
|
|
246
263
|
end
|
247
264
|
|
248
265
|
def marshal_load(variables)
|
249
|
-
initialize(variables[0], ::Time.send!(:get_zone, variables[1]), variables[2])
|
266
|
+
initialize(variables[0].utc, ::Time.send!(:get_zone, variables[1]), variables[2].utc)
|
250
267
|
end
|
251
268
|
|
252
269
|
# Ensure proxy class responds to all methods that underlying time instance responds to.
|
@@ -279,5 +296,9 @@ module ActiveSupport
|
|
279
296
|
def transfer_time_values_to_utc_constructor(time)
|
280
297
|
::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, time.respond_to?(:usec) ? time.usec : 0)
|
281
298
|
end
|
299
|
+
|
300
|
+
def duration_of_variable_length?(obj)
|
301
|
+
ActiveSupport::Duration === obj && obj.parts.flatten.detect {|p| [:years, :months, :days].include? p }
|
302
|
+
end
|
282
303
|
end
|
283
304
|
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# * Retrieve and display zones with a friendlier name (e.g., "Eastern Time (US & Canada)" instead of "America/New_York").
|
5
5
|
# * Lazily load TZInfo::Timezone instances only when they're needed.
|
6
6
|
# * Create ActiveSupport::TimeWithZone instances via TimeZone's +local+, +parse+, +at+ and +now+ methods.
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# If you set <tt>config.time_zone</tt> in the Rails Initializer, you can access this TimeZone object via <tt>Time.zone</tt>:
|
9
9
|
#
|
10
10
|
# # environment.rb:
|
@@ -16,379 +16,381 @@
|
|
16
16
|
# Time.zone.name # => "Eastern Time (US & Canada)"
|
17
17
|
# Time.zone.now # => Sun, 18 May 2008 14:30:44 EDT -04:00
|
18
18
|
#
|
19
|
-
# The version of TZInfo bundled with Active Support only includes the definitions necessary to support the zones
|
19
|
+
# The version of TZInfo bundled with Active Support only includes the definitions necessary to support the zones
|
20
20
|
# defined by the TimeZone class. If you need to use zones that aren't defined by TimeZone, you'll need to install the TZInfo gem
|
21
21
|
# (if a recent version of the gem is installed locally, this will be used instead of the bundled version.)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
include Comparable
|
173
|
-
attr_reader :name
|
22
|
+
module ActiveSupport
|
23
|
+
class TimeZone
|
24
|
+
unless const_defined?(:MAPPING)
|
25
|
+
# Keys are Rails TimeZone names, values are TZInfo identifiers
|
26
|
+
MAPPING = {
|
27
|
+
"International Date Line West" => "Pacific/Midway",
|
28
|
+
"Midway Island" => "Pacific/Midway",
|
29
|
+
"Samoa" => "Pacific/Pago_Pago",
|
30
|
+
"Hawaii" => "Pacific/Honolulu",
|
31
|
+
"Alaska" => "America/Juneau",
|
32
|
+
"Pacific Time (US & Canada)" => "America/Los_Angeles",
|
33
|
+
"Tijuana" => "America/Tijuana",
|
34
|
+
"Mountain Time (US & Canada)" => "America/Denver",
|
35
|
+
"Arizona" => "America/Phoenix",
|
36
|
+
"Chihuahua" => "America/Chihuahua",
|
37
|
+
"Mazatlan" => "America/Mazatlan",
|
38
|
+
"Central Time (US & Canada)" => "America/Chicago",
|
39
|
+
"Saskatchewan" => "America/Regina",
|
40
|
+
"Guadalajara" => "America/Mexico_City",
|
41
|
+
"Mexico City" => "America/Mexico_City",
|
42
|
+
"Monterrey" => "America/Monterrey",
|
43
|
+
"Central America" => "America/Guatemala",
|
44
|
+
"Eastern Time (US & Canada)" => "America/New_York",
|
45
|
+
"Indiana (East)" => "America/Indiana/Indianapolis",
|
46
|
+
"Bogota" => "America/Bogota",
|
47
|
+
"Lima" => "America/Lima",
|
48
|
+
"Quito" => "America/Lima",
|
49
|
+
"Atlantic Time (Canada)" => "America/Halifax",
|
50
|
+
"Caracas" => "America/Caracas",
|
51
|
+
"La Paz" => "America/La_Paz",
|
52
|
+
"Santiago" => "America/Santiago",
|
53
|
+
"Newfoundland" => "America/St_Johns",
|
54
|
+
"Brasilia" => "America/Argentina/Buenos_Aires",
|
55
|
+
"Buenos Aires" => "America/Argentina/Buenos_Aires",
|
56
|
+
"Georgetown" => "America/Argentina/San_Juan",
|
57
|
+
"Greenland" => "America/Godthab",
|
58
|
+
"Mid-Atlantic" => "Atlantic/South_Georgia",
|
59
|
+
"Azores" => "Atlantic/Azores",
|
60
|
+
"Cape Verde Is." => "Atlantic/Cape_Verde",
|
61
|
+
"Dublin" => "Europe/Dublin",
|
62
|
+
"Edinburgh" => "Europe/Dublin",
|
63
|
+
"Lisbon" => "Europe/Lisbon",
|
64
|
+
"London" => "Europe/London",
|
65
|
+
"Casablanca" => "Africa/Casablanca",
|
66
|
+
"Monrovia" => "Africa/Monrovia",
|
67
|
+
"UTC" => "Etc/UTC",
|
68
|
+
"Belgrade" => "Europe/Belgrade",
|
69
|
+
"Bratislava" => "Europe/Bratislava",
|
70
|
+
"Budapest" => "Europe/Budapest",
|
71
|
+
"Ljubljana" => "Europe/Ljubljana",
|
72
|
+
"Prague" => "Europe/Prague",
|
73
|
+
"Sarajevo" => "Europe/Sarajevo",
|
74
|
+
"Skopje" => "Europe/Skopje",
|
75
|
+
"Warsaw" => "Europe/Warsaw",
|
76
|
+
"Zagreb" => "Europe/Zagreb",
|
77
|
+
"Brussels" => "Europe/Brussels",
|
78
|
+
"Copenhagen" => "Europe/Copenhagen",
|
79
|
+
"Madrid" => "Europe/Madrid",
|
80
|
+
"Paris" => "Europe/Paris",
|
81
|
+
"Amsterdam" => "Europe/Amsterdam",
|
82
|
+
"Berlin" => "Europe/Berlin",
|
83
|
+
"Bern" => "Europe/Berlin",
|
84
|
+
"Rome" => "Europe/Rome",
|
85
|
+
"Stockholm" => "Europe/Stockholm",
|
86
|
+
"Vienna" => "Europe/Vienna",
|
87
|
+
"West Central Africa" => "Africa/Algiers",
|
88
|
+
"Bucharest" => "Europe/Bucharest",
|
89
|
+
"Cairo" => "Africa/Cairo",
|
90
|
+
"Helsinki" => "Europe/Helsinki",
|
91
|
+
"Kyev" => "Europe/Kiev",
|
92
|
+
"Riga" => "Europe/Riga",
|
93
|
+
"Sofia" => "Europe/Sofia",
|
94
|
+
"Tallinn" => "Europe/Tallinn",
|
95
|
+
"Vilnius" => "Europe/Vilnius",
|
96
|
+
"Athens" => "Europe/Athens",
|
97
|
+
"Istanbul" => "Europe/Istanbul",
|
98
|
+
"Minsk" => "Europe/Minsk",
|
99
|
+
"Jerusalem" => "Asia/Jerusalem",
|
100
|
+
"Harare" => "Africa/Harare",
|
101
|
+
"Pretoria" => "Africa/Johannesburg",
|
102
|
+
"Moscow" => "Europe/Moscow",
|
103
|
+
"St. Petersburg" => "Europe/Moscow",
|
104
|
+
"Volgograd" => "Europe/Moscow",
|
105
|
+
"Kuwait" => "Asia/Kuwait",
|
106
|
+
"Riyadh" => "Asia/Riyadh",
|
107
|
+
"Nairobi" => "Africa/Nairobi",
|
108
|
+
"Baghdad" => "Asia/Baghdad",
|
109
|
+
"Tehran" => "Asia/Tehran",
|
110
|
+
"Abu Dhabi" => "Asia/Muscat",
|
111
|
+
"Muscat" => "Asia/Muscat",
|
112
|
+
"Baku" => "Asia/Baku",
|
113
|
+
"Tbilisi" => "Asia/Tbilisi",
|
114
|
+
"Yerevan" => "Asia/Yerevan",
|
115
|
+
"Kabul" => "Asia/Kabul",
|
116
|
+
"Ekaterinburg" => "Asia/Yekaterinburg",
|
117
|
+
"Islamabad" => "Asia/Karachi",
|
118
|
+
"Karachi" => "Asia/Karachi",
|
119
|
+
"Tashkent" => "Asia/Tashkent",
|
120
|
+
"Chennai" => "Asia/Kolkata",
|
121
|
+
"Kolkata" => "Asia/Kolkata",
|
122
|
+
"Mumbai" => "Asia/Kolkata",
|
123
|
+
"New Delhi" => "Asia/Kolkata",
|
124
|
+
"Kathmandu" => "Asia/Katmandu",
|
125
|
+
"Astana" => "Asia/Dhaka",
|
126
|
+
"Dhaka" => "Asia/Dhaka",
|
127
|
+
"Sri Jayawardenepura" => "Asia/Dhaka",
|
128
|
+
"Almaty" => "Asia/Almaty",
|
129
|
+
"Novosibirsk" => "Asia/Novosibirsk",
|
130
|
+
"Rangoon" => "Asia/Rangoon",
|
131
|
+
"Bangkok" => "Asia/Bangkok",
|
132
|
+
"Hanoi" => "Asia/Bangkok",
|
133
|
+
"Jakarta" => "Asia/Jakarta",
|
134
|
+
"Krasnoyarsk" => "Asia/Krasnoyarsk",
|
135
|
+
"Beijing" => "Asia/Shanghai",
|
136
|
+
"Chongqing" => "Asia/Chongqing",
|
137
|
+
"Hong Kong" => "Asia/Hong_Kong",
|
138
|
+
"Urumqi" => "Asia/Urumqi",
|
139
|
+
"Kuala Lumpur" => "Asia/Kuala_Lumpur",
|
140
|
+
"Singapore" => "Asia/Singapore",
|
141
|
+
"Taipei" => "Asia/Taipei",
|
142
|
+
"Perth" => "Australia/Perth",
|
143
|
+
"Irkutsk" => "Asia/Irkutsk",
|
144
|
+
"Ulaan Bataar" => "Asia/Ulaanbaatar",
|
145
|
+
"Seoul" => "Asia/Seoul",
|
146
|
+
"Osaka" => "Asia/Tokyo",
|
147
|
+
"Sapporo" => "Asia/Tokyo",
|
148
|
+
"Tokyo" => "Asia/Tokyo",
|
149
|
+
"Yakutsk" => "Asia/Yakutsk",
|
150
|
+
"Darwin" => "Australia/Darwin",
|
151
|
+
"Adelaide" => "Australia/Adelaide",
|
152
|
+
"Canberra" => "Australia/Melbourne",
|
153
|
+
"Melbourne" => "Australia/Melbourne",
|
154
|
+
"Sydney" => "Australia/Sydney",
|
155
|
+
"Brisbane" => "Australia/Brisbane",
|
156
|
+
"Hobart" => "Australia/Hobart",
|
157
|
+
"Vladivostok" => "Asia/Vladivostok",
|
158
|
+
"Guam" => "Pacific/Guam",
|
159
|
+
"Port Moresby" => "Pacific/Port_Moresby",
|
160
|
+
"Magadan" => "Asia/Magadan",
|
161
|
+
"Solomon Is." => "Asia/Magadan",
|
162
|
+
"New Caledonia" => "Pacific/Noumea",
|
163
|
+
"Fiji" => "Pacific/Fiji",
|
164
|
+
"Kamchatka" => "Asia/Kamchatka",
|
165
|
+
"Marshall Is." => "Pacific/Majuro",
|
166
|
+
"Auckland" => "Pacific/Auckland",
|
167
|
+
"Wellington" => "Pacific/Auckland",
|
168
|
+
"Nuku'alofa" => "Pacific/Tongatapu"
|
169
|
+
}.each { |name, zone| name.freeze; zone.freeze }
|
170
|
+
MAPPING.freeze
|
171
|
+
end
|
174
172
|
|
175
|
-
|
176
|
-
|
177
|
-
# (GMT). Seconds were chosen as the offset unit because that is the unit that
|
178
|
-
# Ruby uses to represent time zone offsets (see Time#utc_offset).
|
179
|
-
def initialize(name, utc_offset, tzinfo = nil)
|
180
|
-
@name = name
|
181
|
-
@utc_offset = utc_offset
|
182
|
-
@tzinfo = tzinfo
|
183
|
-
end
|
173
|
+
include Comparable
|
174
|
+
attr_reader :name
|
184
175
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
176
|
+
# Create a new TimeZone object with the given name and offset. The
|
177
|
+
# offset is the number of seconds that this time zone is offset from UTC
|
178
|
+
# (GMT). Seconds were chosen as the offset unit because that is the unit that
|
179
|
+
# Ruby uses to represent time zone offsets (see Time#utc_offset).
|
180
|
+
def initialize(name, utc_offset, tzinfo = nil)
|
181
|
+
@name = name
|
182
|
+
@utc_offset = utc_offset
|
183
|
+
@tzinfo = tzinfo
|
184
|
+
end
|
194
185
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
result = (utc_offset <=> zone.utc_offset)
|
199
|
-
result = (name <=> zone.name) if result == 0
|
200
|
-
result
|
201
|
-
end
|
186
|
+
def utc_offset
|
187
|
+
@utc_offset ||= tzinfo.current_period.utc_offset
|
188
|
+
end
|
202
189
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
190
|
+
# Returns the offset of this time zone as a formatted string, of the
|
191
|
+
# format "+HH:MM".
|
192
|
+
def formatted_offset(colon=true, alternate_utc_string = nil)
|
193
|
+
utc_offset == 0 && alternate_utc_string || utc_offset.to_utc_offset_s(colon)
|
194
|
+
end
|
207
195
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
end
|
196
|
+
# Compare this time zone to the parameter. The two are comapred first on
|
197
|
+
# their offsets, and then by name.
|
198
|
+
def <=>(zone)
|
199
|
+
result = (utc_offset <=> zone.utc_offset)
|
200
|
+
result = (name <=> zone.name) if result == 0
|
201
|
+
result
|
202
|
+
end
|
216
203
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
# Time.zone.at(946684800.0) # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
222
|
-
def at(secs)
|
223
|
-
utc = Time.at(secs).utc rescue DateTime.civil(1970).since(secs)
|
224
|
-
utc.in_time_zone(self)
|
225
|
-
end
|
204
|
+
# Returns a textual representation of this time zone.
|
205
|
+
def to_s
|
206
|
+
"(GMT#{formatted_offset}) #{name}"
|
207
|
+
end
|
226
208
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
#
|
234
|
-
# Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
235
|
-
# Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00
|
236
|
-
def parse(str, now=now)
|
237
|
-
date_parts = Date._parse(str)
|
238
|
-
return if date_parts.blank?
|
239
|
-
time = Time.parse(str, now) rescue DateTime.parse(str)
|
240
|
-
if date_parts[:offset].nil?
|
209
|
+
# Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from given values. Example:
|
210
|
+
#
|
211
|
+
# Time.zone = "Hawaii" # => "Hawaii"
|
212
|
+
# Time.zone.local(2007, 2, 1, 15, 30, 45) # => Thu, 01 Feb 2007 15:30:45 HST -10:00
|
213
|
+
def local(*args)
|
214
|
+
time = Time.utc_time(*args)
|
241
215
|
ActiveSupport::TimeWithZone.new(nil, self, time)
|
242
|
-
else
|
243
|
-
time.in_time_zone(self)
|
244
216
|
end
|
245
|
-
end
|
246
217
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
218
|
+
# Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from number of seconds since the Unix epoch. Example:
|
219
|
+
#
|
220
|
+
# Time.zone = "Hawaii" # => "Hawaii"
|
221
|
+
# Time.utc(2000).to_f # => 946684800.0
|
222
|
+
# Time.zone.at(946684800.0) # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
223
|
+
def at(secs)
|
224
|
+
utc = Time.at(secs).utc rescue DateTime.civil(1970).since(secs)
|
225
|
+
utc.in_time_zone(self)
|
226
|
+
end
|
255
227
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
228
|
+
# Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from parsed string. Example:
|
229
|
+
#
|
230
|
+
# Time.zone = "Hawaii" # => "Hawaii"
|
231
|
+
# Time.zone.parse('1999-12-31 14:00:00') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
232
|
+
#
|
233
|
+
# If upper components are missing from the string, they are supplied from TimeZone#now:
|
234
|
+
#
|
235
|
+
# Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
236
|
+
# Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00
|
237
|
+
def parse(str, now=now)
|
238
|
+
date_parts = Date._parse(str)
|
239
|
+
return if date_parts.blank?
|
240
|
+
time = Time.parse(str, now) rescue DateTime.parse(str)
|
241
|
+
if date_parts[:offset].nil?
|
242
|
+
ActiveSupport::TimeWithZone.new(nil, self, time)
|
243
|
+
else
|
244
|
+
time.in_time_zone(self)
|
245
|
+
end
|
246
|
+
end
|
260
247
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
248
|
+
# Returns an ActiveSupport::TimeWithZone instance representing the current time
|
249
|
+
# in the time zone represented by +self+. Example:
|
250
|
+
#
|
251
|
+
# Time.zone = 'Hawaii' # => "Hawaii"
|
252
|
+
# Time.zone.now # => Wed, 23 Jan 2008 20:24:27 HST -10:00
|
253
|
+
def now
|
254
|
+
Time.now.utc.in_time_zone(self)
|
255
|
+
end
|
266
256
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
257
|
+
# Return the current date in this time zone.
|
258
|
+
def today
|
259
|
+
tzinfo.now.to_date
|
260
|
+
end
|
271
261
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
262
|
+
# Adjust the given time to the simultaneous time in the time zone represented by +self+. Returns a
|
263
|
+
# Time.utc() instance -- if you want an ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.
|
264
|
+
def utc_to_local(time)
|
265
|
+
tzinfo.utc_to_local(time)
|
266
|
+
end
|
276
267
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
268
|
+
# Adjust the given time to the simultaneous time in UTC. Returns a Time.utc() instance.
|
269
|
+
def local_to_utc(time, dst=true)
|
270
|
+
tzinfo.local_to_utc(time, dst)
|
271
|
+
end
|
281
272
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
273
|
+
# Available so that TimeZone instances respond like TZInfo::Timezone instances
|
274
|
+
def period_for_utc(time)
|
275
|
+
tzinfo.period_for_utc(time)
|
276
|
+
end
|
286
277
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
[[-39_600, "International Date Line West", "Midway Island", "Samoa" ],
|
291
|
-
[-36_000, "Hawaii" ],
|
292
|
-
[-32_400, "Alaska" ],
|
293
|
-
[-28_800, "Pacific Time (US & Canada)", "Tijuana" ],
|
294
|
-
[-25_200, "Mountain Time (US & Canada)", "Chihuahua", "Mazatlan",
|
295
|
-
"Arizona" ],
|
296
|
-
[-21_600, "Central Time (US & Canada)", "Saskatchewan", "Guadalajara",
|
297
|
-
"Mexico City", "Monterrey", "Central America" ],
|
298
|
-
[-18_000, "Eastern Time (US & Canada)", "Indiana (East)", "Bogota",
|
299
|
-
"Lima", "Quito" ],
|
300
|
-
[-14_400, "Atlantic Time (Canada)", "Caracas", "La Paz", "Santiago" ],
|
301
|
-
[-12_600, "Newfoundland" ],
|
302
|
-
[-10_800, "Brasilia", "Buenos Aires", "Georgetown", "Greenland" ],
|
303
|
-
[ -7_200, "Mid-Atlantic" ],
|
304
|
-
[ -3_600, "Azores", "Cape Verde Is." ],
|
305
|
-
[ 0, "Dublin", "Edinburgh", "Lisbon", "London", "Casablanca",
|
306
|
-
"Monrovia", "UTC" ],
|
307
|
-
[ 3_600, "Belgrade", "Bratislava", "Budapest", "Ljubljana", "Prague",
|
308
|
-
"Sarajevo", "Skopje", "Warsaw", "Zagreb", "Brussels",
|
309
|
-
"Copenhagen", "Madrid", "Paris", "Amsterdam", "Berlin",
|
310
|
-
"Bern", "Rome", "Stockholm", "Vienna",
|
311
|
-
"West Central Africa" ],
|
312
|
-
[ 7_200, "Bucharest", "Cairo", "Helsinki", "Kyev", "Riga", "Sofia",
|
313
|
-
"Tallinn", "Vilnius", "Athens", "Istanbul", "Minsk",
|
314
|
-
"Jerusalem", "Harare", "Pretoria" ],
|
315
|
-
[ 10_800, "Moscow", "St. Petersburg", "Volgograd", "Kuwait", "Riyadh",
|
316
|
-
"Nairobi", "Baghdad" ],
|
317
|
-
[ 12_600, "Tehran" ],
|
318
|
-
[ 14_400, "Abu Dhabi", "Muscat", "Baku", "Tbilisi", "Yerevan" ],
|
319
|
-
[ 16_200, "Kabul" ],
|
320
|
-
[ 18_000, "Ekaterinburg", "Islamabad", "Karachi", "Tashkent" ],
|
321
|
-
[ 19_800, "Chennai", "Kolkata", "Mumbai", "New Delhi" ],
|
322
|
-
[ 20_700, "Kathmandu" ],
|
323
|
-
[ 21_600, "Astana", "Dhaka", "Sri Jayawardenepura", "Almaty",
|
324
|
-
"Novosibirsk" ],
|
325
|
-
[ 23_400, "Rangoon" ],
|
326
|
-
[ 25_200, "Bangkok", "Hanoi", "Jakarta", "Krasnoyarsk" ],
|
327
|
-
[ 28_800, "Beijing", "Chongqing", "Hong Kong", "Urumqi",
|
328
|
-
"Kuala Lumpur", "Singapore", "Taipei", "Perth", "Irkutsk",
|
329
|
-
"Ulaan Bataar" ],
|
330
|
-
[ 32_400, "Seoul", "Osaka", "Sapporo", "Tokyo", "Yakutsk" ],
|
331
|
-
[ 34_200, "Darwin", "Adelaide" ],
|
332
|
-
[ 36_000, "Canberra", "Melbourne", "Sydney", "Brisbane", "Hobart",
|
333
|
-
"Vladivostok", "Guam", "Port Moresby" ],
|
334
|
-
[ 39_600, "Magadan", "Solomon Is.", "New Caledonia" ],
|
335
|
-
[ 43_200, "Fiji", "Kamchatka", "Marshall Is.", "Auckland",
|
336
|
-
"Wellington" ],
|
337
|
-
[ 46_800, "Nuku'alofa" ]].
|
338
|
-
each do |offset, *places|
|
339
|
-
places.each do |place|
|
340
|
-
place.freeze
|
341
|
-
zone = new(place, offset)
|
342
|
-
ZONES << zone
|
343
|
-
ZONES_MAP[place] = zone
|
344
|
-
end
|
278
|
+
# Available so that TimeZone instances respond like TZInfo::Timezone instances
|
279
|
+
def period_for_local(time, dst=true)
|
280
|
+
tzinfo.period_for_local(time, dst)
|
345
281
|
end
|
346
|
-
ZONES.sort!
|
347
|
-
ZONES.freeze
|
348
|
-
ZONES_MAP.freeze
|
349
282
|
|
350
|
-
|
351
|
-
|
352
|
-
|
283
|
+
# TODO: Preload instead of lazy load for thread safety
|
284
|
+
def tzinfo
|
285
|
+
@tzinfo ||= TZInfo::Timezone.get(MAPPING[name])
|
286
|
+
end
|
353
287
|
|
354
|
-
|
355
|
-
|
288
|
+
unless const_defined?(:ZONES)
|
289
|
+
ZONES = []
|
290
|
+
ZONES_MAP = {}
|
291
|
+
[[-39_600, "International Date Line West", "Midway Island", "Samoa" ],
|
292
|
+
[-36_000, "Hawaii" ],
|
293
|
+
[-32_400, "Alaska" ],
|
294
|
+
[-28_800, "Pacific Time (US & Canada)", "Tijuana" ],
|
295
|
+
[-25_200, "Mountain Time (US & Canada)", "Chihuahua", "Mazatlan",
|
296
|
+
"Arizona" ],
|
297
|
+
[-21_600, "Central Time (US & Canada)", "Saskatchewan", "Guadalajara",
|
298
|
+
"Mexico City", "Monterrey", "Central America" ],
|
299
|
+
[-18_000, "Eastern Time (US & Canada)", "Indiana (East)", "Bogota",
|
300
|
+
"Lima", "Quito" ],
|
301
|
+
[-14_400, "Atlantic Time (Canada)", "Caracas", "La Paz", "Santiago" ],
|
302
|
+
[-12_600, "Newfoundland" ],
|
303
|
+
[-10_800, "Brasilia", "Buenos Aires", "Georgetown", "Greenland" ],
|
304
|
+
[ -7_200, "Mid-Atlantic" ],
|
305
|
+
[ -3_600, "Azores", "Cape Verde Is." ],
|
306
|
+
[ 0, "Dublin", "Edinburgh", "Lisbon", "London", "Casablanca",
|
307
|
+
"Monrovia", "UTC" ],
|
308
|
+
[ 3_600, "Belgrade", "Bratislava", "Budapest", "Ljubljana", "Prague",
|
309
|
+
"Sarajevo", "Skopje", "Warsaw", "Zagreb", "Brussels",
|
310
|
+
"Copenhagen", "Madrid", "Paris", "Amsterdam", "Berlin",
|
311
|
+
"Bern", "Rome", "Stockholm", "Vienna",
|
312
|
+
"West Central Africa" ],
|
313
|
+
[ 7_200, "Bucharest", "Cairo", "Helsinki", "Kyev", "Riga", "Sofia",
|
314
|
+
"Tallinn", "Vilnius", "Athens", "Istanbul", "Minsk",
|
315
|
+
"Jerusalem", "Harare", "Pretoria" ],
|
316
|
+
[ 10_800, "Moscow", "St. Petersburg", "Volgograd", "Kuwait", "Riyadh",
|
317
|
+
"Nairobi", "Baghdad" ],
|
318
|
+
[ 12_600, "Tehran" ],
|
319
|
+
[ 14_400, "Abu Dhabi", "Muscat", "Baku", "Tbilisi", "Yerevan" ],
|
320
|
+
[ 16_200, "Kabul" ],
|
321
|
+
[ 18_000, "Ekaterinburg", "Islamabad", "Karachi", "Tashkent" ],
|
322
|
+
[ 19_800, "Chennai", "Kolkata", "Mumbai", "New Delhi" ],
|
323
|
+
[ 20_700, "Kathmandu" ],
|
324
|
+
[ 21_600, "Astana", "Dhaka", "Sri Jayawardenepura", "Almaty",
|
325
|
+
"Novosibirsk" ],
|
326
|
+
[ 23_400, "Rangoon" ],
|
327
|
+
[ 25_200, "Bangkok", "Hanoi", "Jakarta", "Krasnoyarsk" ],
|
328
|
+
[ 28_800, "Beijing", "Chongqing", "Hong Kong", "Urumqi",
|
329
|
+
"Kuala Lumpur", "Singapore", "Taipei", "Perth", "Irkutsk",
|
330
|
+
"Ulaan Bataar" ],
|
331
|
+
[ 32_400, "Seoul", "Osaka", "Sapporo", "Tokyo", "Yakutsk" ],
|
332
|
+
[ 34_200, "Darwin", "Adelaide" ],
|
333
|
+
[ 36_000, "Canberra", "Melbourne", "Sydney", "Brisbane", "Hobart",
|
334
|
+
"Vladivostok", "Guam", "Port Moresby" ],
|
335
|
+
[ 39_600, "Magadan", "Solomon Is.", "New Caledonia" ],
|
336
|
+
[ 43_200, "Fiji", "Kamchatka", "Marshall Is.", "Auckland",
|
337
|
+
"Wellington" ],
|
338
|
+
[ 46_800, "Nuku'alofa" ]].
|
339
|
+
each do |offset, *places|
|
340
|
+
places.each do |place|
|
341
|
+
place.freeze
|
342
|
+
zone = new(place, offset)
|
343
|
+
ZONES << zone
|
344
|
+
ZONES_MAP[place] = zone
|
345
|
+
end
|
346
|
+
end
|
347
|
+
ZONES.sort!
|
348
|
+
ZONES.freeze
|
349
|
+
ZONES_MAP.freeze
|
356
350
|
|
357
|
-
|
358
|
-
|
359
|
-
# this class with the +composed_of+ macro.)
|
360
|
-
def new(name)
|
361
|
-
self[name]
|
351
|
+
US_ZONES = ZONES.find_all { |z| z.name =~ /US|Arizona|Indiana|Hawaii|Alaska/ }
|
352
|
+
US_ZONES.freeze
|
362
353
|
end
|
363
354
|
|
364
|
-
|
365
|
-
|
366
|
-
# for users to find their own time zone.
|
367
|
-
def all
|
368
|
-
ZONES
|
369
|
-
end
|
355
|
+
class << self
|
356
|
+
alias_method :create, :new
|
370
357
|
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
def [](arg)
|
377
|
-
case arg
|
378
|
-
when String
|
379
|
-
ZONES_MAP[arg]
|
380
|
-
when Numeric, ActiveSupport::Duration
|
381
|
-
arg *= 3600 if arg.abs <= 13
|
382
|
-
all.find { |z| z.utc_offset == arg.to_i }
|
383
|
-
else
|
384
|
-
raise ArgumentError, "invalid argument to TimeZone[]: #{arg.inspect}"
|
358
|
+
# Return a TimeZone instance with the given name, or +nil+ if no
|
359
|
+
# such TimeZone instance exists. (This exists to support the use of
|
360
|
+
# this class with the +composed_of+ macro.)
|
361
|
+
def new(name)
|
362
|
+
self[name]
|
385
363
|
end
|
386
|
-
end
|
387
364
|
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
365
|
+
# Return an array of all TimeZone objects. There are multiple
|
366
|
+
# TimeZone objects per time zone, in many cases, to make it easier
|
367
|
+
# for users to find their own time zone.
|
368
|
+
def all
|
369
|
+
ZONES
|
370
|
+
end
|
371
|
+
|
372
|
+
# Locate a specific time zone object. If the argument is a string, it
|
373
|
+
# is interpreted to mean the name of the timezone to locate. If it is a
|
374
|
+
# numeric value it is either the hour offset, or the second offset, of the
|
375
|
+
# timezone to find. (The first one with that offset will be returned.)
|
376
|
+
# Returns +nil+ if no such time zone is known to the system.
|
377
|
+
def [](arg)
|
378
|
+
case arg
|
379
|
+
when String
|
380
|
+
ZONES_MAP[arg]
|
381
|
+
when Numeric, ActiveSupport::Duration
|
382
|
+
arg *= 3600 if arg.abs <= 13
|
383
|
+
all.find { |z| z.utc_offset == arg.to_i }
|
384
|
+
else
|
385
|
+
raise ArgumentError, "invalid argument to TimeZone[]: #{arg.inspect}"
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
# A convenience method for returning a collection of TimeZone objects
|
390
|
+
# for time zones in the USA.
|
391
|
+
def us_zones
|
392
|
+
US_ZONES
|
393
|
+
end
|
392
394
|
end
|
393
395
|
end
|
394
396
|
end
|