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.

Files changed (236) hide show
  1. data/CHANGELOG +183 -5
  2. data/lib/active_support.rb +6 -2
  3. data/lib/active_support/base64.rb +5 -0
  4. data/lib/active_support/basic_object.rb +23 -4
  5. data/lib/active_support/buffered_logger.rb +17 -3
  6. data/lib/active_support/cache.rb +145 -0
  7. data/lib/active_support/cache/compressed_mem_cache_store.rb +15 -0
  8. data/lib/active_support/cache/drb_store.rb +15 -0
  9. data/lib/active_support/cache/file_store.rb +70 -0
  10. data/lib/active_support/cache/mem_cache_store.rb +100 -0
  11. data/lib/active_support/cache/memory_store.rb +38 -0
  12. data/lib/active_support/callbacks.rb +275 -0
  13. data/lib/active_support/core_ext/array/access.rb +2 -4
  14. data/lib/active_support/core_ext/array/conversions.rb +89 -5
  15. data/lib/active_support/core_ext/array/extract_options.rb +2 -1
  16. data/lib/active_support/core_ext/array/grouping.rb +3 -8
  17. data/lib/active_support/core_ext/array/random_access.rb +1 -1
  18. data/lib/active_support/core_ext/base64.rb +4 -0
  19. data/lib/active_support/core_ext/base64/encoding.rb +13 -0
  20. data/lib/active_support/core_ext/benchmark.rb +12 -0
  21. data/lib/active_support/core_ext/bigdecimal.rb +4 -0
  22. data/lib/active_support/core_ext/bigdecimal/conversions.rb +39 -4
  23. data/lib/active_support/core_ext/blank.rb +5 -2
  24. data/lib/active_support/core_ext/class/attribute_accessors.rb +7 -1
  25. data/lib/active_support/core_ext/class/delegating_attributes.rb +7 -1
  26. data/lib/active_support/core_ext/class/inheritable_attributes.rb +1 -1
  27. data/lib/active_support/core_ext/class/removal.rb +26 -0
  28. data/lib/active_support/core_ext/date/calculations.rb +28 -1
  29. data/lib/active_support/core_ext/date/conversions.rb +1 -0
  30. data/lib/active_support/core_ext/date_time.rb +2 -0
  31. data/lib/active_support/core_ext/date_time/calculations.rb +37 -2
  32. data/lib/active_support/core_ext/date_time/conversions.rb +27 -14
  33. data/lib/active_support/core_ext/enumerable.rb +16 -9
  34. data/lib/active_support/core_ext/exception.rb +8 -0
  35. data/lib/active_support/core_ext/file.rb +6 -6
  36. data/lib/active_support/core_ext/hash/conversions.rb +26 -8
  37. data/lib/active_support/core_ext/hash/indifferent_access.rb +35 -0
  38. data/lib/active_support/core_ext/hash/reverse_merge.rb +4 -1
  39. data/lib/active_support/core_ext/integer/even_odd.rb +10 -5
  40. data/lib/active_support/core_ext/integer/inflections.rb +0 -1
  41. data/lib/active_support/core_ext/kernel/daemonizing.rb +2 -10
  42. data/lib/active_support/core_ext/kernel/reporting.rb +8 -0
  43. data/lib/active_support/core_ext/module/attr_internal.rb +4 -3
  44. data/lib/active_support/core_ext/module/attribute_accessors.rb +11 -1
  45. data/lib/active_support/core_ext/module/delegation.rb +5 -3
  46. data/lib/active_support/core_ext/module/inclusion.rb +19 -0
  47. data/lib/active_support/core_ext/module/introspection.rb +50 -16
  48. data/lib/active_support/core_ext/module/loading.rb +10 -0
  49. data/lib/active_support/core_ext/numeric.rb +3 -1
  50. data/lib/active_support/core_ext/numeric/conversions.rb +19 -0
  51. data/lib/active_support/core_ext/object/instance_variables.rb +52 -0
  52. data/lib/active_support/core_ext/object/misc.rb +1 -1
  53. data/lib/active_support/core_ext/process.rb +1 -0
  54. data/lib/active_support/core_ext/process/daemon.rb +25 -0
  55. data/lib/active_support/core_ext/range/conversions.rb +5 -1
  56. data/lib/active_support/core_ext/range/include_range.rb +8 -0
  57. data/lib/active_support/core_ext/range/overlaps.rb +3 -0
  58. data/lib/active_support/core_ext/string.rb +5 -10
  59. data/lib/active_support/core_ext/string/access.rb +72 -48
  60. data/lib/active_support/core_ext/string/conversions.rb +4 -4
  61. data/lib/active_support/core_ext/string/filters.rb +26 -0
  62. data/lib/active_support/core_ext/string/inflections.rb +56 -64
  63. data/lib/active_support/core_ext/string/iterators.rb +4 -0
  64. data/lib/active_support/core_ext/string/starts_ends_with.rb +12 -4
  65. data/lib/active_support/core_ext/string/unicode.rb +14 -7
  66. data/lib/active_support/core_ext/symbol.rb +1 -1
  67. data/lib/active_support/core_ext/time.rb +2 -0
  68. data/lib/active_support/core_ext/time/calculations.rb +75 -23
  69. data/lib/active_support/core_ext/time/conversions.rb +22 -35
  70. data/lib/active_support/core_ext/time/zones.rb +86 -0
  71. data/lib/active_support/dependencies.rb +92 -80
  72. data/lib/active_support/deprecation.rb +2 -16
  73. data/lib/active_support/duration.rb +4 -4
  74. data/lib/active_support/gzip.rb +25 -0
  75. data/lib/active_support/inflector.rb +92 -69
  76. data/lib/active_support/json.rb +17 -25
  77. data/lib/active_support/json/decoding.rb +1 -1
  78. data/lib/active_support/json/encoders/date.rb +11 -2
  79. data/lib/active_support/json/encoders/date_time.rb +11 -2
  80. data/lib/active_support/json/encoders/enumerable.rb +2 -2
  81. data/lib/active_support/json/encoders/hash.rb +3 -6
  82. data/lib/active_support/json/encoders/object.rb +1 -1
  83. data/lib/active_support/json/encoders/string.rb +8 -2
  84. data/lib/active_support/json/encoders/time.rb +11 -2
  85. data/lib/active_support/json/encoding.rb +0 -1
  86. data/lib/active_support/multibyte/chars.rb +8 -6
  87. data/lib/active_support/multibyte/handlers/utf8_handler.rb +11 -11
  88. data/lib/active_support/ordered_hash.rb +43 -0
  89. data/lib/active_support/ordered_options.rb +0 -38
  90. data/lib/active_support/test_case.rb +10 -2
  91. data/lib/active_support/testing/default.rb +3 -6
  92. data/lib/active_support/testing/setup_and_teardown.rb +93 -0
  93. data/lib/active_support/time_with_zone.rb +283 -0
  94. data/lib/active_support/values/time_zone.rb +336 -123
  95. data/lib/active_support/vendor.rb +12 -0
  96. data/lib/active_support/vendor/memcache-client-1.5.0/memcache.rb +849 -0
  97. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo.rb +33 -0
  98. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/data_timezone.rb +47 -0
  99. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/data_timezone_info.rb +226 -0
  100. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Algiers.rb +55 -0
  101. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Cairo.rb +219 -0
  102. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Casablanca.rb +38 -0
  103. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Harare.rb +18 -0
  104. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Johannesburg.rb +25 -0
  105. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Monrovia.rb +22 -0
  106. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Nairobi.rb +23 -0
  107. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +166 -0
  108. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Argentina/San_Juan.rb +170 -0
  109. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Bogota.rb +23 -0
  110. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Caracas.rb +23 -0
  111. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Chicago.rb +283 -0
  112. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Chihuahua.rb +136 -0
  113. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Denver.rb +204 -0
  114. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Godthab.rb +161 -0
  115. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Guatemala.rb +27 -0
  116. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Halifax.rb +274 -0
  117. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Indiana/Indianapolis.rb +149 -0
  118. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Juneau.rb +194 -0
  119. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/La_Paz.rb +22 -0
  120. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Lima.rb +35 -0
  121. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Los_Angeles.rb +232 -0
  122. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Mazatlan.rb +139 -0
  123. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Mexico_City.rb +144 -0
  124. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Monterrey.rb +131 -0
  125. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/New_York.rb +282 -0
  126. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Phoenix.rb +30 -0
  127. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Regina.rb +74 -0
  128. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Santiago.rb +205 -0
  129. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/St_Johns.rb +288 -0
  130. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Tijuana.rb +196 -0
  131. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Almaty.rb +67 -0
  132. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Baghdad.rb +73 -0
  133. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Baku.rb +161 -0
  134. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Bangkok.rb +20 -0
  135. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Chongqing.rb +33 -0
  136. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Dhaka.rb +27 -0
  137. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Hong_Kong.rb +87 -0
  138. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Irkutsk.rb +165 -0
  139. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Jakarta.rb +30 -0
  140. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Jerusalem.rb +163 -0
  141. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kabul.rb +20 -0
  142. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kamchatka.rb +163 -0
  143. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Karachi.rb +28 -0
  144. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Katmandu.rb +20 -0
  145. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kolkata.rb +25 -0
  146. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Krasnoyarsk.rb +163 -0
  147. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kuala_Lumpur.rb +31 -0
  148. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kuwait.rb +18 -0
  149. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Magadan.rb +163 -0
  150. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Muscat.rb +18 -0
  151. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Novosibirsk.rb +164 -0
  152. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Rangoon.rb +24 -0
  153. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Riyadh.rb +18 -0
  154. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Seoul.rb +34 -0
  155. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Shanghai.rb +35 -0
  156. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Singapore.rb +33 -0
  157. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Taipei.rb +59 -0
  158. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tashkent.rb +47 -0
  159. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tbilisi.rb +78 -0
  160. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tehran.rb +121 -0
  161. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tokyo.rb +30 -0
  162. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Ulaanbaatar.rb +65 -0
  163. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Urumqi.rb +33 -0
  164. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Vladivostok.rb +164 -0
  165. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yakutsk.rb +163 -0
  166. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yekaterinburg.rb +165 -0
  167. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yerevan.rb +165 -0
  168. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/Azores.rb +270 -0
  169. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/Cape_Verde.rb +23 -0
  170. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/South_Georgia.rb +18 -0
  171. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Adelaide.rb +187 -0
  172. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Brisbane.rb +35 -0
  173. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Darwin.rb +29 -0
  174. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Hobart.rb +193 -0
  175. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Melbourne.rb +185 -0
  176. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Perth.rb +37 -0
  177. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Sydney.rb +185 -0
  178. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Etc/UTC.rb +16 -0
  179. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Amsterdam.rb +228 -0
  180. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Athens.rb +185 -0
  181. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Belgrade.rb +163 -0
  182. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Berlin.rb +188 -0
  183. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Bratislava.rb +13 -0
  184. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Brussels.rb +232 -0
  185. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Bucharest.rb +181 -0
  186. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Budapest.rb +197 -0
  187. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Copenhagen.rb +179 -0
  188. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Dublin.rb +276 -0
  189. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Helsinki.rb +163 -0
  190. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Istanbul.rb +218 -0
  191. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Kiev.rb +168 -0
  192. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Lisbon.rb +268 -0
  193. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Ljubljana.rb +13 -0
  194. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/London.rb +288 -0
  195. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Madrid.rb +211 -0
  196. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Minsk.rb +170 -0
  197. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Moscow.rb +181 -0
  198. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Paris.rb +232 -0
  199. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Prague.rb +187 -0
  200. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Riga.rb +176 -0
  201. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Rome.rb +215 -0
  202. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Sarajevo.rb +13 -0
  203. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Skopje.rb +13 -0
  204. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Sofia.rb +173 -0
  205. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Stockholm.rb +165 -0
  206. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Tallinn.rb +172 -0
  207. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Vienna.rb +183 -0
  208. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Vilnius.rb +170 -0
  209. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Warsaw.rb +212 -0
  210. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Zagreb.rb +13 -0
  211. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Auckland.rb +202 -0
  212. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Fiji.rb +23 -0
  213. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Guam.rb +22 -0
  214. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Honolulu.rb +28 -0
  215. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Majuro.rb +20 -0
  216. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Midway.rb +25 -0
  217. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Noumea.rb +25 -0
  218. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Pago_Pago.rb +26 -0
  219. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Port_Moresby.rb +20 -0
  220. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Tongatapu.rb +27 -0
  221. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/info_timezone.rb +52 -0
  222. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/linked_timezone.rb +51 -0
  223. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/linked_timezone_info.rb +44 -0
  224. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/offset_rationals.rb +95 -0
  225. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/time_or_datetime.rb +292 -0
  226. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone.rb +508 -0
  227. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_definition.rb +56 -0
  228. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_info.rb +40 -0
  229. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_offset_info.rb +94 -0
  230. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_period.rb +198 -0
  231. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_transition_info.rb +138 -0
  232. data/lib/active_support/version.rb +2 -2
  233. data/lib/active_support/whiny_nil.rb +30 -10
  234. metadata +175 -5
  235. data/lib/active_support/core_ext/rexml.rb +0 -38
  236. data/lib/active_support/testing.rb +0 -1
@@ -1,61 +1,195 @@
1
- # A value object representing a time zone. A time zone is simply a named
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
- # A TimeZone instance may be used to convert a Time value to the corresponding
6
- # time zone.
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
- # The class also includes #all, which returns a list of all TimeZone objects.
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
- include Comparable
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
- attr_reader :name, :utc_offset
172
+ include Comparable
173
+ attr_reader :name
13
174
 
14
- # Create a new TimeZone object with the given name and offset. The offset is
15
- # the number of seconds that this time zone is offset from UTC (GMT). Seconds
16
- # were chosen as the offset unit because that is the unit that Ruby uses
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
- # Returns the offset of this time zone as a formatted string, of the
24
- # format "+HH:MM". If the offset is zero, this returns the empty
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
- # Adjust the given time to the time zone represented by +self+.
47
- def adjust(time)
48
- time = time.to_time unless time.is_a?(::Time)
49
- time + utc_offset - time.utc_offset
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
- "(UTC#{formatted_offset}) #{name}"
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
- @@zones = nil
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
- class << self
77
- # Create a new TimeZone instance with the given name and offset.
78
- def create(name, offset)
79
- zone = allocate
80
- zone.send!(:initialize, name, offset)
81
- zone
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 #composed_of macro.)
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 TimeZone
92
- # objects per time zone, in many cases, to make it easier for users to
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
- unless @@zones
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
- all.find { |z| z.name == arg }
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
- all.find_all { |z| z.name =~ US_ZONES }
391
+ US_ZONES
179
392
  end
180
393
  end
181
394
  end