activesupport 2.0.5 → 2.1.0
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 +183 -5
- data/lib/active_support.rb +6 -2
- data/lib/active_support/base64.rb +5 -0
- data/lib/active_support/basic_object.rb +23 -4
- data/lib/active_support/buffered_logger.rb +17 -3
- data/lib/active_support/cache.rb +145 -0
- data/lib/active_support/cache/compressed_mem_cache_store.rb +15 -0
- data/lib/active_support/cache/drb_store.rb +15 -0
- data/lib/active_support/cache/file_store.rb +70 -0
- data/lib/active_support/cache/mem_cache_store.rb +100 -0
- data/lib/active_support/cache/memory_store.rb +38 -0
- data/lib/active_support/callbacks.rb +275 -0
- data/lib/active_support/core_ext/array/access.rb +2 -4
- data/lib/active_support/core_ext/array/conversions.rb +89 -5
- data/lib/active_support/core_ext/array/extract_options.rb +2 -1
- data/lib/active_support/core_ext/array/grouping.rb +3 -8
- data/lib/active_support/core_ext/array/random_access.rb +1 -1
- data/lib/active_support/core_ext/base64.rb +4 -0
- data/lib/active_support/core_ext/base64/encoding.rb +13 -0
- data/lib/active_support/core_ext/benchmark.rb +12 -0
- data/lib/active_support/core_ext/bigdecimal.rb +4 -0
- data/lib/active_support/core_ext/bigdecimal/conversions.rb +39 -4
- data/lib/active_support/core_ext/blank.rb +5 -2
- data/lib/active_support/core_ext/class/attribute_accessors.rb +7 -1
- data/lib/active_support/core_ext/class/delegating_attributes.rb +7 -1
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +1 -1
- data/lib/active_support/core_ext/class/removal.rb +26 -0
- data/lib/active_support/core_ext/date/calculations.rb +28 -1
- data/lib/active_support/core_ext/date/conversions.rb +1 -0
- data/lib/active_support/core_ext/date_time.rb +2 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +37 -2
- data/lib/active_support/core_ext/date_time/conversions.rb +27 -14
- data/lib/active_support/core_ext/enumerable.rb +16 -9
- data/lib/active_support/core_ext/exception.rb +8 -0
- data/lib/active_support/core_ext/file.rb +6 -6
- data/lib/active_support/core_ext/hash/conversions.rb +26 -8
- data/lib/active_support/core_ext/hash/indifferent_access.rb +35 -0
- data/lib/active_support/core_ext/hash/reverse_merge.rb +4 -1
- data/lib/active_support/core_ext/integer/even_odd.rb +10 -5
- data/lib/active_support/core_ext/integer/inflections.rb +0 -1
- data/lib/active_support/core_ext/kernel/daemonizing.rb +2 -10
- data/lib/active_support/core_ext/kernel/reporting.rb +8 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +4 -3
- data/lib/active_support/core_ext/module/attribute_accessors.rb +11 -1
- data/lib/active_support/core_ext/module/delegation.rb +5 -3
- data/lib/active_support/core_ext/module/inclusion.rb +19 -0
- data/lib/active_support/core_ext/module/introspection.rb +50 -16
- data/lib/active_support/core_ext/module/loading.rb +10 -0
- data/lib/active_support/core_ext/numeric.rb +3 -1
- data/lib/active_support/core_ext/numeric/conversions.rb +19 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +52 -0
- data/lib/active_support/core_ext/object/misc.rb +1 -1
- data/lib/active_support/core_ext/process.rb +1 -0
- data/lib/active_support/core_ext/process/daemon.rb +25 -0
- data/lib/active_support/core_ext/range/conversions.rb +5 -1
- data/lib/active_support/core_ext/range/include_range.rb +8 -0
- data/lib/active_support/core_ext/range/overlaps.rb +3 -0
- data/lib/active_support/core_ext/string.rb +5 -10
- data/lib/active_support/core_ext/string/access.rb +72 -48
- data/lib/active_support/core_ext/string/conversions.rb +4 -4
- data/lib/active_support/core_ext/string/filters.rb +26 -0
- data/lib/active_support/core_ext/string/inflections.rb +56 -64
- data/lib/active_support/core_ext/string/iterators.rb +4 -0
- data/lib/active_support/core_ext/string/starts_ends_with.rb +12 -4
- data/lib/active_support/core_ext/string/unicode.rb +14 -7
- data/lib/active_support/core_ext/symbol.rb +1 -1
- data/lib/active_support/core_ext/time.rb +2 -0
- data/lib/active_support/core_ext/time/calculations.rb +75 -23
- data/lib/active_support/core_ext/time/conversions.rb +22 -35
- data/lib/active_support/core_ext/time/zones.rb +86 -0
- data/lib/active_support/dependencies.rb +92 -80
- data/lib/active_support/deprecation.rb +2 -16
- data/lib/active_support/duration.rb +4 -4
- data/lib/active_support/gzip.rb +25 -0
- data/lib/active_support/inflector.rb +92 -69
- data/lib/active_support/json.rb +17 -25
- data/lib/active_support/json/decoding.rb +1 -1
- data/lib/active_support/json/encoders/date.rb +11 -2
- data/lib/active_support/json/encoders/date_time.rb +11 -2
- data/lib/active_support/json/encoders/enumerable.rb +2 -2
- data/lib/active_support/json/encoders/hash.rb +3 -6
- data/lib/active_support/json/encoders/object.rb +1 -1
- data/lib/active_support/json/encoders/string.rb +8 -2
- data/lib/active_support/json/encoders/time.rb +11 -2
- data/lib/active_support/json/encoding.rb +0 -1
- data/lib/active_support/multibyte/chars.rb +8 -6
- data/lib/active_support/multibyte/handlers/utf8_handler.rb +11 -11
- data/lib/active_support/ordered_hash.rb +43 -0
- data/lib/active_support/ordered_options.rb +0 -38
- data/lib/active_support/test_case.rb +10 -2
- data/lib/active_support/testing/default.rb +3 -6
- data/lib/active_support/testing/setup_and_teardown.rb +93 -0
- data/lib/active_support/time_with_zone.rb +283 -0
- data/lib/active_support/values/time_zone.rb +336 -123
- data/lib/active_support/vendor.rb +12 -0
- data/lib/active_support/vendor/memcache-client-1.5.0/memcache.rb +849 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo.rb +33 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/data_timezone.rb +47 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/data_timezone_info.rb +226 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Algiers.rb +55 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Cairo.rb +219 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Casablanca.rb +38 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Harare.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Johannesburg.rb +25 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Monrovia.rb +22 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Nairobi.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +166 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Argentina/San_Juan.rb +170 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Bogota.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Caracas.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Chicago.rb +283 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Chihuahua.rb +136 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Denver.rb +204 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Godthab.rb +161 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Guatemala.rb +27 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Halifax.rb +274 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Indiana/Indianapolis.rb +149 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Juneau.rb +194 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/La_Paz.rb +22 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Lima.rb +35 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Los_Angeles.rb +232 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Mazatlan.rb +139 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Mexico_City.rb +144 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Monterrey.rb +131 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/New_York.rb +282 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Phoenix.rb +30 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Regina.rb +74 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Santiago.rb +205 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/St_Johns.rb +288 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Tijuana.rb +196 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Almaty.rb +67 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Baghdad.rb +73 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Baku.rb +161 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Bangkok.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Chongqing.rb +33 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Dhaka.rb +27 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Hong_Kong.rb +87 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Irkutsk.rb +165 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Jakarta.rb +30 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Jerusalem.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kabul.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kamchatka.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Karachi.rb +28 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Katmandu.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kolkata.rb +25 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Krasnoyarsk.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kuala_Lumpur.rb +31 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kuwait.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Magadan.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Muscat.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Novosibirsk.rb +164 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Rangoon.rb +24 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Riyadh.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Seoul.rb +34 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Shanghai.rb +35 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Singapore.rb +33 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Taipei.rb +59 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tashkent.rb +47 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tbilisi.rb +78 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tehran.rb +121 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tokyo.rb +30 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Ulaanbaatar.rb +65 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Urumqi.rb +33 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Vladivostok.rb +164 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yakutsk.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yekaterinburg.rb +165 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yerevan.rb +165 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/Azores.rb +270 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/Cape_Verde.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/South_Georgia.rb +18 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Adelaide.rb +187 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Brisbane.rb +35 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Darwin.rb +29 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Hobart.rb +193 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Melbourne.rb +185 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Perth.rb +37 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Sydney.rb +185 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Etc/UTC.rb +16 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Amsterdam.rb +228 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Athens.rb +185 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Belgrade.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Berlin.rb +188 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Bratislava.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Brussels.rb +232 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Bucharest.rb +181 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Budapest.rb +197 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Copenhagen.rb +179 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Dublin.rb +276 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Helsinki.rb +163 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Istanbul.rb +218 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Kiev.rb +168 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Lisbon.rb +268 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Ljubljana.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/London.rb +288 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Madrid.rb +211 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Minsk.rb +170 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Moscow.rb +181 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Paris.rb +232 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Prague.rb +187 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Riga.rb +176 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Rome.rb +215 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Sarajevo.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Skopje.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Sofia.rb +173 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Stockholm.rb +165 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Tallinn.rb +172 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Vienna.rb +183 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Vilnius.rb +170 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Warsaw.rb +212 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Zagreb.rb +13 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Auckland.rb +202 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Fiji.rb +23 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Guam.rb +22 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Honolulu.rb +28 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Majuro.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Midway.rb +25 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Noumea.rb +25 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Pago_Pago.rb +26 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Port_Moresby.rb +20 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Tongatapu.rb +27 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/info_timezone.rb +52 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/linked_timezone.rb +51 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/linked_timezone_info.rb +44 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/offset_rationals.rb +95 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/time_or_datetime.rb +292 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone.rb +508 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_definition.rb +56 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_info.rb +40 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_offset_info.rb +94 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_period.rb +198 -0
- data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_transition_info.rb +138 -0
- data/lib/active_support/version.rb +2 -2
- data/lib/active_support/whiny_nil.rb +30 -10
- metadata +175 -5
- data/lib/active_support/core_ext/rexml.rb +0 -38
- data/lib/active_support/testing.rb +0 -1
@@ -1,61 +1,195 @@
|
|
1
|
-
#
|
2
|
-
# offset (in seconds) from GMT. Note that two time zone objects are only
|
3
|
-
# equivalent if they have both the same offset, and the same name.
|
1
|
+
# The TimeZone class serves as a wrapper around TZInfo::Timezone instances. It allows us to do the following:
|
4
2
|
#
|
5
|
-
#
|
6
|
-
#
|
3
|
+
# * Limit the set of zones provided by TZInfo to a meaningful subset of 142 zones.
|
4
|
+
# * Retrieve and display zones with a friendlier name (e.g., "Eastern Time (US & Canada)" instead of "America/New_York").
|
5
|
+
# * Lazily load TZInfo::Timezone instances only when they're needed.
|
6
|
+
# * Create ActiveSupport::TimeWithZone instances via TimeZone's +local+, +parse+, +at+ and +now+ methods.
|
7
|
+
#
|
8
|
+
# If you set <tt>config.time_zone</tt> in the Rails Initializer, you can access this TimeZone object via <tt>Time.zone</tt>:
|
7
9
|
#
|
8
|
-
#
|
10
|
+
# # environment.rb:
|
11
|
+
# Rails::Initializer.run do |config|
|
12
|
+
# config.time_zone = "Eastern Time (US & Canada)"
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# Time.zone # => #<TimeZone:0x514834...>
|
16
|
+
# Time.zone.name # => "Eastern Time (US & Canada)"
|
17
|
+
# Time.zone.now # => Sun, 18 May 2008 14:30:44 EDT -04:00
|
18
|
+
#
|
19
|
+
# The version of TZInfo bundled with Active Support only includes the definitions necessary to support the zones
|
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
|
+
# (if a recent version of the gem is installed locally, this will be used instead of the bundled version.)
|
9
22
|
class TimeZone
|
10
|
-
|
23
|
+
unless const_defined?(:MAPPING)
|
24
|
+
# Keys are Rails TimeZone names, values are TZInfo identifiers
|
25
|
+
MAPPING = {
|
26
|
+
"International Date Line West" => "Pacific/Midway",
|
27
|
+
"Midway Island" => "Pacific/Midway",
|
28
|
+
"Samoa" => "Pacific/Pago_Pago",
|
29
|
+
"Hawaii" => "Pacific/Honolulu",
|
30
|
+
"Alaska" => "America/Juneau",
|
31
|
+
"Pacific Time (US & Canada)" => "America/Los_Angeles",
|
32
|
+
"Tijuana" => "America/Tijuana",
|
33
|
+
"Mountain Time (US & Canada)" => "America/Denver",
|
34
|
+
"Arizona" => "America/Phoenix",
|
35
|
+
"Chihuahua" => "America/Chihuahua",
|
36
|
+
"Mazatlan" => "America/Mazatlan",
|
37
|
+
"Central Time (US & Canada)" => "America/Chicago",
|
38
|
+
"Saskatchewan" => "America/Regina",
|
39
|
+
"Guadalajara" => "America/Mexico_City",
|
40
|
+
"Mexico City" => "America/Mexico_City",
|
41
|
+
"Monterrey" => "America/Monterrey",
|
42
|
+
"Central America" => "America/Guatemala",
|
43
|
+
"Eastern Time (US & Canada)" => "America/New_York",
|
44
|
+
"Indiana (East)" => "America/Indiana/Indianapolis",
|
45
|
+
"Bogota" => "America/Bogota",
|
46
|
+
"Lima" => "America/Lima",
|
47
|
+
"Quito" => "America/Lima",
|
48
|
+
"Atlantic Time (Canada)" => "America/Halifax",
|
49
|
+
"Caracas" => "America/Caracas",
|
50
|
+
"La Paz" => "America/La_Paz",
|
51
|
+
"Santiago" => "America/Santiago",
|
52
|
+
"Newfoundland" => "America/St_Johns",
|
53
|
+
"Brasilia" => "America/Argentina/Buenos_Aires",
|
54
|
+
"Buenos Aires" => "America/Argentina/Buenos_Aires",
|
55
|
+
"Georgetown" => "America/Argentina/San_Juan",
|
56
|
+
"Greenland" => "America/Godthab",
|
57
|
+
"Mid-Atlantic" => "Atlantic/South_Georgia",
|
58
|
+
"Azores" => "Atlantic/Azores",
|
59
|
+
"Cape Verde Is." => "Atlantic/Cape_Verde",
|
60
|
+
"Dublin" => "Europe/Dublin",
|
61
|
+
"Edinburgh" => "Europe/Dublin",
|
62
|
+
"Lisbon" => "Europe/Lisbon",
|
63
|
+
"London" => "Europe/London",
|
64
|
+
"Casablanca" => "Africa/Casablanca",
|
65
|
+
"Monrovia" => "Africa/Monrovia",
|
66
|
+
"UTC" => "Etc/UTC",
|
67
|
+
"Belgrade" => "Europe/Belgrade",
|
68
|
+
"Bratislava" => "Europe/Bratislava",
|
69
|
+
"Budapest" => "Europe/Budapest",
|
70
|
+
"Ljubljana" => "Europe/Ljubljana",
|
71
|
+
"Prague" => "Europe/Prague",
|
72
|
+
"Sarajevo" => "Europe/Sarajevo",
|
73
|
+
"Skopje" => "Europe/Skopje",
|
74
|
+
"Warsaw" => "Europe/Warsaw",
|
75
|
+
"Zagreb" => "Europe/Zagreb",
|
76
|
+
"Brussels" => "Europe/Brussels",
|
77
|
+
"Copenhagen" => "Europe/Copenhagen",
|
78
|
+
"Madrid" => "Europe/Madrid",
|
79
|
+
"Paris" => "Europe/Paris",
|
80
|
+
"Amsterdam" => "Europe/Amsterdam",
|
81
|
+
"Berlin" => "Europe/Berlin",
|
82
|
+
"Bern" => "Europe/Berlin",
|
83
|
+
"Rome" => "Europe/Rome",
|
84
|
+
"Stockholm" => "Europe/Stockholm",
|
85
|
+
"Vienna" => "Europe/Vienna",
|
86
|
+
"West Central Africa" => "Africa/Algiers",
|
87
|
+
"Bucharest" => "Europe/Bucharest",
|
88
|
+
"Cairo" => "Africa/Cairo",
|
89
|
+
"Helsinki" => "Europe/Helsinki",
|
90
|
+
"Kyev" => "Europe/Kiev",
|
91
|
+
"Riga" => "Europe/Riga",
|
92
|
+
"Sofia" => "Europe/Sofia",
|
93
|
+
"Tallinn" => "Europe/Tallinn",
|
94
|
+
"Vilnius" => "Europe/Vilnius",
|
95
|
+
"Athens" => "Europe/Athens",
|
96
|
+
"Istanbul" => "Europe/Istanbul",
|
97
|
+
"Minsk" => "Europe/Minsk",
|
98
|
+
"Jerusalem" => "Asia/Jerusalem",
|
99
|
+
"Harare" => "Africa/Harare",
|
100
|
+
"Pretoria" => "Africa/Johannesburg",
|
101
|
+
"Moscow" => "Europe/Moscow",
|
102
|
+
"St. Petersburg" => "Europe/Moscow",
|
103
|
+
"Volgograd" => "Europe/Moscow",
|
104
|
+
"Kuwait" => "Asia/Kuwait",
|
105
|
+
"Riyadh" => "Asia/Riyadh",
|
106
|
+
"Nairobi" => "Africa/Nairobi",
|
107
|
+
"Baghdad" => "Asia/Baghdad",
|
108
|
+
"Tehran" => "Asia/Tehran",
|
109
|
+
"Abu Dhabi" => "Asia/Muscat",
|
110
|
+
"Muscat" => "Asia/Muscat",
|
111
|
+
"Baku" => "Asia/Baku",
|
112
|
+
"Tbilisi" => "Asia/Tbilisi",
|
113
|
+
"Yerevan" => "Asia/Yerevan",
|
114
|
+
"Kabul" => "Asia/Kabul",
|
115
|
+
"Ekaterinburg" => "Asia/Yekaterinburg",
|
116
|
+
"Islamabad" => "Asia/Karachi",
|
117
|
+
"Karachi" => "Asia/Karachi",
|
118
|
+
"Tashkent" => "Asia/Tashkent",
|
119
|
+
"Chennai" => "Asia/Kolkata",
|
120
|
+
"Kolkata" => "Asia/Kolkata",
|
121
|
+
"Mumbai" => "Asia/Kolkata",
|
122
|
+
"New Delhi" => "Asia/Kolkata",
|
123
|
+
"Kathmandu" => "Asia/Katmandu",
|
124
|
+
"Astana" => "Asia/Dhaka",
|
125
|
+
"Dhaka" => "Asia/Dhaka",
|
126
|
+
"Sri Jayawardenepura" => "Asia/Dhaka",
|
127
|
+
"Almaty" => "Asia/Almaty",
|
128
|
+
"Novosibirsk" => "Asia/Novosibirsk",
|
129
|
+
"Rangoon" => "Asia/Rangoon",
|
130
|
+
"Bangkok" => "Asia/Bangkok",
|
131
|
+
"Hanoi" => "Asia/Bangkok",
|
132
|
+
"Jakarta" => "Asia/Jakarta",
|
133
|
+
"Krasnoyarsk" => "Asia/Krasnoyarsk",
|
134
|
+
"Beijing" => "Asia/Shanghai",
|
135
|
+
"Chongqing" => "Asia/Chongqing",
|
136
|
+
"Hong Kong" => "Asia/Hong_Kong",
|
137
|
+
"Urumqi" => "Asia/Urumqi",
|
138
|
+
"Kuala Lumpur" => "Asia/Kuala_Lumpur",
|
139
|
+
"Singapore" => "Asia/Singapore",
|
140
|
+
"Taipei" => "Asia/Taipei",
|
141
|
+
"Perth" => "Australia/Perth",
|
142
|
+
"Irkutsk" => "Asia/Irkutsk",
|
143
|
+
"Ulaan Bataar" => "Asia/Ulaanbaatar",
|
144
|
+
"Seoul" => "Asia/Seoul",
|
145
|
+
"Osaka" => "Asia/Tokyo",
|
146
|
+
"Sapporo" => "Asia/Tokyo",
|
147
|
+
"Tokyo" => "Asia/Tokyo",
|
148
|
+
"Yakutsk" => "Asia/Yakutsk",
|
149
|
+
"Darwin" => "Australia/Darwin",
|
150
|
+
"Adelaide" => "Australia/Adelaide",
|
151
|
+
"Canberra" => "Australia/Melbourne",
|
152
|
+
"Melbourne" => "Australia/Melbourne",
|
153
|
+
"Sydney" => "Australia/Sydney",
|
154
|
+
"Brisbane" => "Australia/Brisbane",
|
155
|
+
"Hobart" => "Australia/Hobart",
|
156
|
+
"Vladivostok" => "Asia/Vladivostok",
|
157
|
+
"Guam" => "Pacific/Guam",
|
158
|
+
"Port Moresby" => "Pacific/Port_Moresby",
|
159
|
+
"Magadan" => "Asia/Magadan",
|
160
|
+
"Solomon Is." => "Asia/Magadan",
|
161
|
+
"New Caledonia" => "Pacific/Noumea",
|
162
|
+
"Fiji" => "Pacific/Fiji",
|
163
|
+
"Kamchatka" => "Asia/Kamchatka",
|
164
|
+
"Marshall Is." => "Pacific/Majuro",
|
165
|
+
"Auckland" => "Pacific/Auckland",
|
166
|
+
"Wellington" => "Pacific/Auckland",
|
167
|
+
"Nuku'alofa" => "Pacific/Tongatapu"
|
168
|
+
}.each { |name, zone| name.freeze; zone.freeze }
|
169
|
+
MAPPING.freeze
|
170
|
+
end
|
11
171
|
|
12
|
-
|
172
|
+
include Comparable
|
173
|
+
attr_reader :name
|
13
174
|
|
14
|
-
# Create a new TimeZone object with the given name and offset. The
|
15
|
-
# the number of seconds that this time zone is offset from UTC
|
16
|
-
# were chosen as the offset unit because that is the unit that
|
17
|
-
# to represent time zone offsets (see Time#utc_offset).
|
18
|
-
def initialize(name, utc_offset)
|
175
|
+
# Create a new TimeZone object with the given name and offset. The
|
176
|
+
# offset is the number of seconds that this time zone is offset from UTC
|
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)
|
19
180
|
@name = name
|
20
181
|
@utc_offset = utc_offset
|
182
|
+
@tzinfo = tzinfo
|
21
183
|
end
|
22
184
|
|
23
|
-
|
24
|
-
|
25
|
-
# string. If +colon+ is false, a colon will not be inserted into the
|
26
|
-
# result.
|
27
|
-
def formatted_offset( colon=true )
|
28
|
-
return "" if utc_offset == 0
|
29
|
-
sign = (utc_offset < 0 ? -1 : 1)
|
30
|
-
hours = utc_offset.abs / 3600
|
31
|
-
minutes = (utc_offset.abs % 3600) / 60
|
32
|
-
"%+03d%s%02d" % [ hours * sign, colon ? ":" : "", minutes ]
|
33
|
-
end
|
34
|
-
|
35
|
-
# Compute and return the current time, in the time zone represented by
|
36
|
-
# +self+.
|
37
|
-
def now
|
38
|
-
adjust(Time.now)
|
39
|
-
end
|
40
|
-
|
41
|
-
# Return the current date in this time zone.
|
42
|
-
def today
|
43
|
-
now.to_date
|
185
|
+
def utc_offset
|
186
|
+
@utc_offset ||= tzinfo.current_period.utc_offset
|
44
187
|
end
|
45
188
|
|
46
|
-
#
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
# Reinterprets the given time value as a time in the current time
|
53
|
-
# zone, and then adjusts it to return the corresponding time in the
|
54
|
-
# local time zone.
|
55
|
-
def unadjust(time)
|
56
|
-
time = time.to_time unless time.is_a?(::Time)
|
57
|
-
time = time.localtime
|
58
|
-
time - utc_offset - time.utc_offset
|
189
|
+
# Returns the offset of this time zone as a formatted string, of the
|
190
|
+
# format "+HH:MM".
|
191
|
+
def formatted_offset(colon=true, alternate_utc_string = nil)
|
192
|
+
utc_offset == 0 && alternate_utc_string || utc_offset.to_utc_offset_s(colon)
|
59
193
|
end
|
60
194
|
|
61
195
|
# Compare this time zone to the parameter. The two are comapred first on
|
@@ -68,87 +202,170 @@ class TimeZone
|
|
68
202
|
|
69
203
|
# Returns a textual representation of this time zone.
|
70
204
|
def to_s
|
71
|
-
"(
|
205
|
+
"(GMT#{formatted_offset}) #{name}"
|
206
|
+
end
|
207
|
+
|
208
|
+
# Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from given values. Example:
|
209
|
+
#
|
210
|
+
# Time.zone = "Hawaii" # => "Hawaii"
|
211
|
+
# Time.zone.local(2007, 2, 1, 15, 30, 45) # => Thu, 01 Feb 2007 15:30:45 HST -10:00
|
212
|
+
def local(*args)
|
213
|
+
time = Time.utc_time(*args)
|
214
|
+
ActiveSupport::TimeWithZone.new(nil, self, time)
|
72
215
|
end
|
73
216
|
|
74
|
-
|
217
|
+
# Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from number of seconds since the Unix epoch. Example:
|
218
|
+
#
|
219
|
+
# Time.zone = "Hawaii" # => "Hawaii"
|
220
|
+
# Time.utc(2000).to_f # => 946684800.0
|
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
|
75
226
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
227
|
+
# Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from parsed string. Example:
|
228
|
+
#
|
229
|
+
# Time.zone = "Hawaii" # => "Hawaii"
|
230
|
+
# Time.zone.parse('1999-12-31 14:00:00') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
231
|
+
#
|
232
|
+
# If upper components are missing from the string, they are supplied from TimeZone#now:
|
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?
|
241
|
+
ActiveSupport::TimeWithZone.new(nil, self, time)
|
242
|
+
else
|
243
|
+
time.in_time_zone(self)
|
82
244
|
end
|
245
|
+
end
|
246
|
+
|
247
|
+
# Returns an ActiveSupport::TimeWithZone instance representing the current time
|
248
|
+
# in the time zone represented by +self+. Example:
|
249
|
+
#
|
250
|
+
# Time.zone = 'Hawaii' # => "Hawaii"
|
251
|
+
# Time.zone.now # => Wed, 23 Jan 2008 20:24:27 HST -10:00
|
252
|
+
def now
|
253
|
+
Time.now.utc.in_time_zone(self)
|
254
|
+
end
|
255
|
+
|
256
|
+
# Return the current date in this time zone.
|
257
|
+
def today
|
258
|
+
tzinfo.now.to_date
|
259
|
+
end
|
260
|
+
|
261
|
+
# Adjust the given time to the simultaneous time in the time zone represented by +self+. Returns a
|
262
|
+
# Time.utc() instance -- if you want an ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.
|
263
|
+
def utc_to_local(time)
|
264
|
+
tzinfo.utc_to_local(time)
|
265
|
+
end
|
266
|
+
|
267
|
+
# Adjust the given time to the simultaneous time in UTC. Returns a Time.utc() instance.
|
268
|
+
def local_to_utc(time, dst=true)
|
269
|
+
tzinfo.local_to_utc(time, dst)
|
270
|
+
end
|
271
|
+
|
272
|
+
# Available so that TimeZone instances respond like TZInfo::Timezone instances
|
273
|
+
def period_for_utc(time)
|
274
|
+
tzinfo.period_for_utc(time)
|
275
|
+
end
|
276
|
+
|
277
|
+
# Available so that TimeZone instances respond like TZInfo::Timezone instances
|
278
|
+
def period_for_local(time, dst=true)
|
279
|
+
tzinfo.period_for_local(time, dst)
|
280
|
+
end
|
281
|
+
|
282
|
+
# TODO: Preload instead of lazy load for thread safety
|
283
|
+
def tzinfo
|
284
|
+
@tzinfo ||= TZInfo::Timezone.get(MAPPING[name])
|
285
|
+
end
|
286
|
+
|
287
|
+
unless const_defined?(:ZONES)
|
288
|
+
ZONES = []
|
289
|
+
ZONES_MAP = {}
|
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
|
345
|
+
end
|
346
|
+
ZONES.sort!
|
347
|
+
ZONES.freeze
|
348
|
+
ZONES_MAP.freeze
|
349
|
+
|
350
|
+
US_ZONES = ZONES.find_all { |z| z.name =~ /US|Arizona|Indiana|Hawaii|Alaska/ }
|
351
|
+
US_ZONES.freeze
|
352
|
+
end
|
353
|
+
|
354
|
+
class << self
|
355
|
+
alias_method :create, :new
|
83
356
|
|
84
357
|
# Return a TimeZone instance with the given name, or +nil+ if no
|
85
358
|
# such TimeZone instance exists. (This exists to support the use of
|
86
|
-
# this class with the
|
359
|
+
# this class with the +composed_of+ macro.)
|
87
360
|
def new(name)
|
88
361
|
self[name]
|
89
362
|
end
|
90
363
|
|
91
|
-
# Return an array of all TimeZone objects. There are multiple
|
92
|
-
# objects per time zone, in many cases, to make it easier
|
93
|
-
# find their own time zone.
|
364
|
+
# Return an array of all TimeZone objects. There are multiple
|
365
|
+
# TimeZone objects per time zone, in many cases, to make it easier
|
366
|
+
# for users to find their own time zone.
|
94
367
|
def all
|
95
|
-
|
96
|
-
@@zones = []
|
97
|
-
[[-43_200, "International Date Line West" ],
|
98
|
-
[-39_600, "Midway Island", "Samoa" ],
|
99
|
-
[-36_000, "Hawaii" ],
|
100
|
-
[-32_400, "Alaska" ],
|
101
|
-
[-28_800, "Pacific Time (US & Canada)", "Tijuana" ],
|
102
|
-
[-25_200, "Mountain Time (US & Canada)", "Chihuahua", "Mazatlan",
|
103
|
-
"Arizona" ],
|
104
|
-
[-21_600, "Central Time (US & Canada)", "Saskatchewan", "Guadalajara",
|
105
|
-
"Mexico City", "Monterrey", "Central America" ],
|
106
|
-
[-18_000, "Eastern Time (US & Canada)", "Indiana (East)", "Bogota",
|
107
|
-
"Lima", "Quito" ],
|
108
|
-
[-14_400, "Atlantic Time (Canada)", "Caracas", "La Paz", "Santiago" ],
|
109
|
-
[-12_600, "Newfoundland" ],
|
110
|
-
[-10_800, "Brasilia", "Buenos Aires", "Georgetown", "Greenland" ],
|
111
|
-
[ -7_200, "Mid-Atlantic" ],
|
112
|
-
[ -3_600, "Azores", "Cape Verde Is." ],
|
113
|
-
[ 0, "Dublin", "Edinburgh", "Lisbon", "London", "Casablanca",
|
114
|
-
"Monrovia" ],
|
115
|
-
[ 3_600, "Belgrade", "Bratislava", "Budapest", "Ljubljana", "Prague",
|
116
|
-
"Sarajevo", "Skopje", "Warsaw", "Zagreb", "Brussels",
|
117
|
-
"Copenhagen", "Madrid", "Paris", "Amsterdam", "Berlin",
|
118
|
-
"Bern", "Rome", "Stockholm", "Vienna",
|
119
|
-
"West Central Africa" ],
|
120
|
-
[ 7_200, "Bucharest", "Cairo", "Helsinki", "Kyev", "Riga", "Sofia",
|
121
|
-
"Tallinn", "Vilnius", "Athens", "Istanbul", "Minsk",
|
122
|
-
"Jerusalem", "Harare", "Pretoria" ],
|
123
|
-
[ 10_800, "Moscow", "St. Petersburg", "Volgograd", "Kuwait", "Riyadh",
|
124
|
-
"Nairobi", "Baghdad" ],
|
125
|
-
[ 12_600, "Tehran" ],
|
126
|
-
[ 14_400, "Abu Dhabi", "Muscat", "Baku", "Tbilisi", "Yerevan" ],
|
127
|
-
[ 16_200, "Kabul" ],
|
128
|
-
[ 18_000, "Ekaterinburg", "Islamabad", "Karachi", "Tashkent" ],
|
129
|
-
[ 19_800, "Chennai", "Kolkata", "Mumbai", "New Delhi" ],
|
130
|
-
[ 20_700, "Kathmandu" ],
|
131
|
-
[ 21_600, "Astana", "Dhaka", "Sri Jayawardenepura", "Almaty",
|
132
|
-
"Novosibirsk" ],
|
133
|
-
[ 23_400, "Rangoon" ],
|
134
|
-
[ 25_200, "Bangkok", "Hanoi", "Jakarta", "Krasnoyarsk" ],
|
135
|
-
[ 28_800, "Beijing", "Chongqing", "Hong Kong", "Urumqi",
|
136
|
-
"Kuala Lumpur", "Singapore", "Taipei", "Perth", "Irkutsk",
|
137
|
-
"Ulaan Bataar" ],
|
138
|
-
[ 32_400, "Seoul", "Osaka", "Sapporo", "Tokyo", "Yakutsk" ],
|
139
|
-
[ 34_200, "Darwin", "Adelaide" ],
|
140
|
-
[ 36_000, "Canberra", "Melbourne", "Sydney", "Brisbane", "Hobart",
|
141
|
-
"Vladivostok", "Guam", "Port Moresby" ],
|
142
|
-
[ 39_600, "Magadan", "Solomon Is.", "New Caledonia" ],
|
143
|
-
[ 43_200, "Fiji", "Kamchatka", "Marshall Is.", "Auckland",
|
144
|
-
"Wellington" ],
|
145
|
-
[ 46_800, "Nuku'alofa" ]].
|
146
|
-
each do |offset, *places|
|
147
|
-
places.each { |place| @@zones << create(place, offset).freeze }
|
148
|
-
end
|
149
|
-
@@zones.sort!
|
150
|
-
end
|
151
|
-
@@zones
|
368
|
+
ZONES
|
152
369
|
end
|
153
370
|
|
154
371
|
# Locate a specific time zone object. If the argument is a string, it
|
@@ -159,8 +376,8 @@ class TimeZone
|
|
159
376
|
def [](arg)
|
160
377
|
case arg
|
161
378
|
when String
|
162
|
-
|
163
|
-
when Numeric
|
379
|
+
ZONES_MAP[arg]
|
380
|
+
when Numeric, ActiveSupport::Duration
|
164
381
|
arg *= 3600 if arg.abs <= 13
|
165
382
|
all.find { |z| z.utc_offset == arg.to_i }
|
166
383
|
else
|
@@ -168,14 +385,10 @@ class TimeZone
|
|
168
385
|
end
|
169
386
|
end
|
170
387
|
|
171
|
-
# A regular expression that matches the names of all time zones in
|
172
|
-
# the USA.
|
173
|
-
US_ZONES = /US|Arizona|Indiana|Hawaii|Alaska/ unless defined?(US_ZONES)
|
174
|
-
|
175
388
|
# A convenience method for returning a collection of TimeZone objects
|
176
389
|
# for time zones in the USA.
|
177
390
|
def us_zones
|
178
|
-
|
391
|
+
US_ZONES
|
179
392
|
end
|
180
393
|
end
|
181
394
|
end
|