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
@@ -0,0 +1,56 @@
1
+ #--
2
+ # Copyright (c) 2006 Philip Ross
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #++
22
+
23
+ require 'tzinfo/data_timezone_info'
24
+ require 'tzinfo/linked_timezone_info'
25
+
26
+ module TZInfo
27
+
28
+ # TimezoneDefinition is included into Timezone definition modules.
29
+ # TimezoneDefinition provides the methods for defining timezones.
30
+ module TimezoneDefinition #:nodoc:
31
+ # Add class methods to the includee.
32
+ def self.append_features(base)
33
+ super
34
+ base.extend(ClassMethods)
35
+ end
36
+
37
+ # Class methods for inclusion.
38
+ module ClassMethods #:nodoc:
39
+ # Returns and yields a DataTimezoneInfo object to define a timezone.
40
+ def timezone(identifier)
41
+ yield @timezone = DataTimezoneInfo.new(identifier)
42
+ end
43
+
44
+ # Defines a linked timezone.
45
+ def linked_timezone(identifier, link_to_identifier)
46
+ @timezone = LinkedTimezoneInfo.new(identifier, link_to_identifier)
47
+ end
48
+
49
+ # Returns the last TimezoneInfo to be defined with timezone or
50
+ # linked_timezone.
51
+ def get
52
+ @timezone
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,40 @@
1
+ #--
2
+ # Copyright (c) 2006 Philip Ross
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #++
22
+
23
+ module TZInfo
24
+ # Represents a timezone defined in a data module.
25
+ class TimezoneInfo #:nodoc:
26
+
27
+ # The timezone identifier.
28
+ attr_reader :identifier
29
+
30
+ # Constructs a new TimezoneInfo with an identifier.
31
+ def initialize(identifier)
32
+ @identifier = identifier
33
+ end
34
+
35
+ # Returns internal object state as a programmer-readable string.
36
+ def inspect
37
+ "#<#{self.class}: #@identifier>"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,94 @@
1
+ #--
2
+ # Copyright (c) 2006 Philip Ross
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #++
22
+
23
+ module TZInfo
24
+ # Represents an offset defined in a Timezone data file.
25
+ class TimezoneOffsetInfo #:nodoc:
26
+ # The base offset of the timezone from UTC in seconds.
27
+ attr_reader :utc_offset
28
+
29
+ # The offset from standard time for the zone in seconds (i.e. non-zero if
30
+ # daylight savings is being observed).
31
+ attr_reader :std_offset
32
+
33
+ # The total offset of this observance from UTC in seconds
34
+ # (utc_offset + std_offset).
35
+ attr_reader :utc_total_offset
36
+
37
+ # The abbreviation that identifies this observance, e.g. "GMT"
38
+ # (Greenwich Mean Time) or "BST" (British Summer Time) for "Europe/London". The returned identifier is a
39
+ # symbol.
40
+ attr_reader :abbreviation
41
+
42
+ # Constructs a new TimezoneOffsetInfo. utc_offset and std_offset are
43
+ # specified in seconds.
44
+ def initialize(utc_offset, std_offset, abbreviation)
45
+ @utc_offset = utc_offset
46
+ @std_offset = std_offset
47
+ @abbreviation = abbreviation
48
+
49
+ @utc_total_offset = @utc_offset + @std_offset
50
+ end
51
+
52
+ # True if std_offset is non-zero.
53
+ def dst?
54
+ @std_offset != 0
55
+ end
56
+
57
+ # Converts a UTC DateTime to local time based on the offset of this period.
58
+ def to_local(utc)
59
+ TimeOrDateTime.wrap(utc) {|utc|
60
+ utc + @utc_total_offset
61
+ }
62
+ end
63
+
64
+ # Converts a local DateTime to UTC based on the offset of this period.
65
+ def to_utc(local)
66
+ TimeOrDateTime.wrap(local) {|local|
67
+ local - @utc_total_offset
68
+ }
69
+ end
70
+
71
+ # Returns true if and only if toi has the same utc_offset, std_offset
72
+ # and abbreviation as this TimezoneOffsetInfo.
73
+ def ==(toi)
74
+ toi.respond_to?(:utc_offset) && toi.respond_to?(:std_offset) && toi.respond_to?(:abbreviation) &&
75
+ utc_offset == toi.utc_offset && std_offset == toi.std_offset && abbreviation == toi.abbreviation
76
+ end
77
+
78
+ # Returns true if and only if toi has the same utc_offset, std_offset
79
+ # and abbreviation as this TimezoneOffsetInfo.
80
+ def eql?(toi)
81
+ self == toi
82
+ end
83
+
84
+ # Returns a hash of this TimezoneOffsetInfo.
85
+ def hash
86
+ utc_offset.hash ^ std_offset.hash ^ abbreviation.hash
87
+ end
88
+
89
+ # Returns internal object state as a programmer-readable string.
90
+ def inspect
91
+ "#<#{self.class}: #@utc_offset,#@std_offset,#@abbreviation>"
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,198 @@
1
+ #--
2
+ # Copyright (c) 2005-2006 Philip Ross
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #++
22
+
23
+ require 'tzinfo/offset_rationals'
24
+ require 'tzinfo/time_or_datetime'
25
+
26
+ module TZInfo
27
+ # A period of time in a timezone where the same offset from UTC applies.
28
+ #
29
+ # All the methods that take times accept instances of Time, DateTime or
30
+ # integer timestamps.
31
+ class TimezonePeriod
32
+ # The TimezoneTransitionInfo that defines the start of this TimezonePeriod
33
+ # (may be nil if unbounded).
34
+ attr_reader :start_transition
35
+
36
+ # The TimezoneTransitionInfo that defines the end of this TimezonePeriod
37
+ # (may be nil if unbounded).
38
+ attr_reader :end_transition
39
+
40
+ # The TimezoneOffsetInfo for this period.
41
+ attr_reader :offset
42
+
43
+ # Initializes a new TimezonePeriod.
44
+ def initialize(start_transition, end_transition, offset = nil)
45
+ @start_transition = start_transition
46
+ @end_transition = end_transition
47
+
48
+ if offset
49
+ raise ArgumentError, 'Offset specified with transitions' if @start_transition || @end_transition
50
+ @offset = offset
51
+ else
52
+ if @start_transition
53
+ @offset = @start_transition.offset
54
+ elsif @end_transition
55
+ @offset = @end_transition.previous_offset
56
+ else
57
+ raise ArgumentError, 'No offset specified and no transitions to determine it from'
58
+ end
59
+ end
60
+
61
+ @utc_total_offset_rational = nil
62
+ end
63
+
64
+ # Base offset of the timezone from UTC (seconds).
65
+ def utc_offset
66
+ @offset.utc_offset
67
+ end
68
+
69
+ # Offset from the local time where daylight savings is in effect (seconds).
70
+ # E.g.: utc_offset could be -5 hours. Normally, std_offset would be 0.
71
+ # During daylight savings, std_offset would typically become +1 hours.
72
+ def std_offset
73
+ @offset.std_offset
74
+ end
75
+
76
+ # The identifier of this period, e.g. "GMT" (Greenwich Mean Time) or "BST"
77
+ # (British Summer Time) for "Europe/London". The returned identifier is a
78
+ # symbol.
79
+ def abbreviation
80
+ @offset.abbreviation
81
+ end
82
+ alias :zone_identifier :abbreviation
83
+
84
+ # Total offset from UTC (seconds). Equal to utc_offset + std_offset.
85
+ def utc_total_offset
86
+ @offset.utc_total_offset
87
+ end
88
+
89
+ # Total offset from UTC (days). Result is a Rational.
90
+ def utc_total_offset_rational
91
+ unless @utc_total_offset_rational
92
+ @utc_total_offset_rational = OffsetRationals.rational_for_offset(utc_total_offset)
93
+ end
94
+ @utc_total_offset_rational
95
+ end
96
+
97
+ # The start time of the period in UTC as a DateTime. May be nil if unbounded.
98
+ def utc_start
99
+ @start_transition ? @start_transition.at.to_datetime : nil
100
+ end
101
+
102
+ # The end time of the period in UTC as a DateTime. May be nil if unbounded.
103
+ def utc_end
104
+ @end_transition ? @end_transition.at.to_datetime : nil
105
+ end
106
+
107
+ # The start time of the period in local time as a DateTime. May be nil if
108
+ # unbounded.
109
+ def local_start
110
+ @start_transition ? @start_transition.local_start.to_datetime : nil
111
+ end
112
+
113
+ # The end time of the period in local time as a DateTime. May be nil if
114
+ # unbounded.
115
+ def local_end
116
+ @end_transition ? @end_transition.local_end.to_datetime : nil
117
+ end
118
+
119
+ # true if daylight savings is in effect for this period; otherwise false.
120
+ def dst?
121
+ @offset.dst?
122
+ end
123
+
124
+ # true if this period is valid for the given UTC DateTime; otherwise false.
125
+ def valid_for_utc?(utc)
126
+ utc_after_start?(utc) && utc_before_end?(utc)
127
+ end
128
+
129
+ # true if the given UTC DateTime is after the start of the period
130
+ # (inclusive); otherwise false.
131
+ def utc_after_start?(utc)
132
+ !@start_transition || @start_transition.at <= utc
133
+ end
134
+
135
+ # true if the given UTC DateTime is before the end of the period
136
+ # (exclusive); otherwise false.
137
+ def utc_before_end?(utc)
138
+ !@end_transition || @end_transition.at > utc
139
+ end
140
+
141
+ # true if this period is valid for the given local DateTime; otherwise false.
142
+ def valid_for_local?(local)
143
+ local_after_start?(local) && local_before_end?(local)
144
+ end
145
+
146
+ # true if the given local DateTime is after the start of the period
147
+ # (inclusive); otherwise false.
148
+ def local_after_start?(local)
149
+ !@start_transition || @start_transition.local_start <= local
150
+ end
151
+
152
+ # true if the given local DateTime is before the end of the period
153
+ # (exclusive); otherwise false.
154
+ def local_before_end?(local)
155
+ !@end_transition || @end_transition.local_end > local
156
+ end
157
+
158
+ # Converts a UTC DateTime to local time based on the offset of this period.
159
+ def to_local(utc)
160
+ @offset.to_local(utc)
161
+ end
162
+
163
+ # Converts a local DateTime to UTC based on the offset of this period.
164
+ def to_utc(local)
165
+ @offset.to_utc(local)
166
+ end
167
+
168
+ # Returns true if this TimezonePeriod is equal to p. This compares the
169
+ # start_transition, end_transition and offset using ==.
170
+ def ==(p)
171
+ p.respond_to?(:start_transition) && p.respond_to?(:end_transition) &&
172
+ p.respond_to?(:offset) && start_transition == p.start_transition &&
173
+ end_transition == p.end_transition && offset == p.offset
174
+ end
175
+
176
+ # Returns true if this TimezonePeriods is equal to p. This compares the
177
+ # start_transition, end_transition and offset using eql?
178
+ def eql?(p)
179
+ p.respond_to?(:start_transition) && p.respond_to?(:end_transition) &&
180
+ p.respond_to?(:offset) && start_transition.eql?(p.start_transition) &&
181
+ end_transition.eql?(p.end_transition) && offset.eql?(p.offset)
182
+ end
183
+
184
+ # Returns a hash of this TimezonePeriod.
185
+ def hash
186
+ result = @start_transition.hash ^ @end_transition.hash
187
+ result ^= @offset.hash unless @start_transition || @end_transition
188
+ result
189
+ end
190
+
191
+ # Returns internal object state as a programmer-readable string.
192
+ def inspect
193
+ result = "#<#{self.class}: #{@start_transition.inspect},#{@end_transition.inspect}"
194
+ result << ",#{@offset.inspect}>" unless @start_transition || @end_transition
195
+ result + '>'
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,138 @@
1
+ #--
2
+ # Copyright (c) 2006 Philip Ross
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #++
22
+
23
+ require 'date'
24
+ require 'tzinfo/time_or_datetime'
25
+
26
+ module TZInfo
27
+ # Represents an offset defined in a Timezone data file.
28
+ class TimezoneTransitionInfo #:nodoc:
29
+ # The offset this transition changes to (a TimezoneOffsetInfo instance).
30
+ attr_reader :offset
31
+
32
+ # The offset this transition changes from (a TimezoneOffsetInfo instance).
33
+ attr_reader :previous_offset
34
+
35
+ # The numerator of the DateTime if the transition time is defined as a
36
+ # DateTime, otherwise the transition time as a timestamp.
37
+ attr_reader :numerator_or_time
38
+ protected :numerator_or_time
39
+
40
+ # Either the denominotor of the DateTime if the transition time is defined
41
+ # as a DateTime, otherwise nil.
42
+ attr_reader :denominator
43
+ protected :denominator
44
+
45
+ # Creates a new TimezoneTransitionInfo with the given offset,
46
+ # previous_offset (both TimezoneOffsetInfo instances) and UTC time.
47
+ # if denominator is nil, numerator_or_time is treated as a number of
48
+ # seconds since the epoch. If denominator is specified numerator_or_time
49
+ # and denominator are used to create a DateTime as follows:
50
+ #
51
+ # DateTime.new!(Rational.new!(numerator_or_time, denominator), 0, Date::ITALY)
52
+ #
53
+ # For performance reasons, the numerator and denominator must be specified
54
+ # in their lowest form.
55
+ def initialize(offset, previous_offset, numerator_or_time, denominator = nil)
56
+ @offset = offset
57
+ @previous_offset = previous_offset
58
+ @numerator_or_time = numerator_or_time
59
+ @denominator = denominator
60
+
61
+ @at = nil
62
+ @local_end = nil
63
+ @local_start = nil
64
+ end
65
+
66
+ # A TimeOrDateTime instance representing the UTC time when this transition
67
+ # occurs.
68
+ def at
69
+ unless @at
70
+ unless @denominator
71
+ @at = TimeOrDateTime.new(@numerator_or_time)
72
+ else
73
+ r = Rational.new!(@numerator_or_time, @denominator)
74
+
75
+ # Ruby 1.8.6 introduced new! and deprecated new0.
76
+ # Ruby 1.9.0 removed new0.
77
+ # We still need to support new0 for older versions of Ruby.
78
+ if DateTime.respond_to? :new!
79
+ dt = DateTime.new!(r, 0, Date::ITALY)
80
+ else
81
+ dt = DateTime.new0(r, 0, Date::ITALY)
82
+ end
83
+
84
+ @at = TimeOrDateTime.new(dt)
85
+ end
86
+ end
87
+
88
+ @at
89
+ end
90
+
91
+ # A TimeOrDateTime instance representing the local time when this transition
92
+ # causes the previous observance to end (calculated from at using
93
+ # previous_offset).
94
+ def local_end
95
+ @local_end = at.add_with_convert(@previous_offset.utc_total_offset) unless @local_end
96
+ @local_end
97
+ end
98
+
99
+ # A TimeOrDateTime instance representing the local time when this transition
100
+ # causes the next observance to start (calculated from at using offset).
101
+ def local_start
102
+ @local_start = at.add_with_convert(@offset.utc_total_offset) unless @local_start
103
+ @local_start
104
+ end
105
+
106
+ # Returns true if this TimezoneTransitionInfo is equal to the given
107
+ # TimezoneTransitionInfo. Two TimezoneTransitionInfo instances are
108
+ # considered to be equal by == if offset, previous_offset and at are all
109
+ # equal.
110
+ def ==(tti)
111
+ tti.respond_to?(:offset) && tti.respond_to?(:previous_offset) && tti.respond_to?(:at) &&
112
+ offset == tti.offset && previous_offset == tti.previous_offset && at == tti.at
113
+ end
114
+
115
+ # Returns true if this TimezoneTransitionInfo is equal to the given
116
+ # TimezoneTransitionInfo. Two TimezoneTransitionInfo instances are
117
+ # considered to be equal by eql? if offset, previous_offset,
118
+ # numerator_or_time and denominator are all equal. This is stronger than ==,
119
+ # which just requires the at times to be equal regardless of how they were
120
+ # originally specified.
121
+ def eql?(tti)
122
+ tti.respond_to?(:offset) && tti.respond_to?(:previous_offset) &&
123
+ tti.respond_to?(:numerator_or_time) && tti.respond_to?(:denominator) &&
124
+ offset == tti.offset && previous_offset == tti.previous_offset &&
125
+ numerator_or_time == tti.numerator_or_time && denominator == tti.denominator
126
+ end
127
+
128
+ # Returns a hash of this TimezoneTransitionInfo instance.
129
+ def hash
130
+ @offset.hash ^ @previous_offset.hash ^ @numerator_or_time.hash ^ @denominator.hash
131
+ end
132
+
133
+ # Returns internal object state as a programmer-readable string.
134
+ def inspect
135
+ "#<#{self.class}: #{at.inspect},#{@offset.inspect}>"
136
+ end
137
+ end
138
+ end