tzinfo 0.0.4 → 0.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 tzinfo might be problematic. Click here for more details.

Files changed (427) hide show
  1. data/CHANGES +94 -58
  2. data/LICENSE +19 -0
  3. data/README +1 -1
  4. data/Rakefile +75 -0
  5. data/lib/tzinfo.rb +14 -14
  6. data/lib/tzinfo/country.rb +38 -6
  7. data/lib/tzinfo/definitions/Africa/Abidjan.rb +2 -2
  8. data/lib/tzinfo/definitions/Africa/Accra.rb +16 -16
  9. data/lib/tzinfo/definitions/Africa/Addis_Ababa.rb +3 -3
  10. data/lib/tzinfo/definitions/Africa/Algiers.rb +35 -35
  11. data/lib/tzinfo/definitions/Africa/Asmera.rb +4 -4
  12. data/lib/tzinfo/definitions/Africa/Bamako.rb +4 -4
  13. data/lib/tzinfo/definitions/Africa/Bangui.rb +2 -2
  14. data/lib/tzinfo/definitions/Africa/Banjul.rb +4 -4
  15. data/lib/tzinfo/definitions/Africa/Bissau.rb +3 -3
  16. data/lib/tzinfo/definitions/Africa/Blantyre.rb +2 -2
  17. data/lib/tzinfo/definitions/Africa/Brazzaville.rb +2 -2
  18. data/lib/tzinfo/definitions/Africa/Bujumbura.rb +2 -2
  19. data/lib/tzinfo/definitions/Africa/Cairo.rb +192 -191
  20. data/lib/tzinfo/definitions/Africa/Casablanca.rb +20 -20
  21. data/lib/tzinfo/definitions/Africa/Ceuta.rb +146 -145
  22. data/lib/tzinfo/definitions/Africa/Conakry.rb +4 -4
  23. data/lib/tzinfo/definitions/Africa/Dakar.rb +3 -3
  24. data/lib/tzinfo/definitions/Africa/Dar_es_Salaam.rb +4 -4
  25. data/lib/tzinfo/definitions/Africa/Djibouti.rb +2 -2
  26. data/lib/tzinfo/definitions/Africa/Douala.rb +2 -2
  27. data/lib/tzinfo/definitions/Africa/El_Aaiun.rb +3 -3
  28. data/lib/tzinfo/definitions/Africa/Freetown.rb +32 -32
  29. data/lib/tzinfo/definitions/Africa/Gaborone.rb +4 -4
  30. data/lib/tzinfo/definitions/Africa/Harare.rb +2 -2
  31. data/lib/tzinfo/definitions/Africa/Johannesburg.rb +7 -7
  32. data/lib/tzinfo/definitions/Africa/Kampala.rb +5 -5
  33. data/lib/tzinfo/definitions/Africa/Khartoum.rb +35 -35
  34. data/lib/tzinfo/definitions/Africa/Kigali.rb +2 -2
  35. data/lib/tzinfo/definitions/Africa/Kinshasa.rb +2 -2
  36. data/lib/tzinfo/definitions/Africa/Lagos.rb +2 -2
  37. data/lib/tzinfo/definitions/Africa/Libreville.rb +2 -2
  38. data/lib/tzinfo/definitions/Africa/Lome.rb +2 -2
  39. data/lib/tzinfo/definitions/Africa/Luanda.rb +3 -3
  40. data/lib/tzinfo/definitions/Africa/Lubumbashi.rb +2 -2
  41. data/lib/tzinfo/definitions/Africa/Lusaka.rb +2 -2
  42. data/lib/tzinfo/definitions/Africa/Malabo.rb +3 -3
  43. data/lib/tzinfo/definitions/Africa/Maputo.rb +2 -2
  44. data/lib/tzinfo/definitions/Africa/Maseru.rb +4 -4
  45. data/lib/tzinfo/definitions/Africa/Mbabane.rb +2 -2
  46. data/lib/tzinfo/definitions/Africa/Mogadishu.rb +4 -4
  47. data/lib/tzinfo/definitions/Africa/Monrovia.rb +4 -4
  48. data/lib/tzinfo/definitions/Africa/Nairobi.rb +5 -5
  49. data/lib/tzinfo/definitions/Africa/Ndjamena.rb +4 -4
  50. data/lib/tzinfo/definitions/Africa/Niamey.rb +4 -4
  51. data/lib/tzinfo/definitions/Africa/Nouakchott.rb +4 -4
  52. data/lib/tzinfo/definitions/Africa/Ouagadougou.rb +2 -2
  53. data/lib/tzinfo/definitions/Africa/Porto__m__Novo.rb +3 -3
  54. data/lib/tzinfo/definitions/Africa/Sao_Tome.rb +3 -3
  55. data/lib/tzinfo/definitions/Africa/Tripoli.rb +30 -30
  56. data/lib/tzinfo/definitions/Africa/Tunis.rb +29 -29
  57. data/lib/tzinfo/definitions/Africa/Windhoek.rb +110 -110
  58. data/lib/tzinfo/definitions/America/Adak.rb +164 -163
  59. data/lib/tzinfo/definitions/America/Anchorage.rb +164 -163
  60. data/lib/tzinfo/definitions/America/Anguilla.rb +2 -2
  61. data/lib/tzinfo/definitions/America/Antigua.rb +3 -3
  62. data/lib/tzinfo/definitions/America/Araguaina.rb +53 -53
  63. data/lib/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +58 -58
  64. data/lib/tzinfo/definitions/America/Argentina/Catamarca.rb +60 -60
  65. data/lib/tzinfo/definitions/America/Argentina/Cordoba.rb +58 -58
  66. data/lib/tzinfo/definitions/America/Argentina/Jujuy.rb +59 -59
  67. data/lib/tzinfo/definitions/America/Argentina/La_Rioja.rb +61 -61
  68. data/lib/tzinfo/definitions/America/Argentina/Mendoza.rb +60 -60
  69. data/lib/tzinfo/definitions/America/Argentina/Rio_Gallegos.rb +60 -60
  70. data/lib/tzinfo/definitions/America/Argentina/San_Juan.rb +61 -61
  71. data/lib/tzinfo/definitions/America/Argentina/Tucuman.rb +60 -60
  72. data/lib/tzinfo/definitions/America/Argentina/Ushuaia.rb +60 -60
  73. data/lib/tzinfo/definitions/America/Aruba.rb +3 -3
  74. data/lib/tzinfo/definitions/America/Asuncion.rb +146 -145
  75. data/lib/tzinfo/definitions/America/Bahia.rb +61 -61
  76. data/lib/tzinfo/definitions/America/Barbados.rb +11 -11
  77. data/lib/tzinfo/definitions/America/Belem.rb +31 -31
  78. data/lib/tzinfo/definitions/America/Belize.rb +56 -56
  79. data/lib/tzinfo/definitions/America/Boa_Vista.rb +36 -36
  80. data/lib/tzinfo/definitions/America/Bogota.rb +5 -5
  81. data/lib/tzinfo/definitions/America/Boise.rb +167 -166
  82. data/lib/tzinfo/definitions/America/Cambridge_Bay.rb +143 -142
  83. data/lib/tzinfo/definitions/America/Campo_Grande.rb +145 -144
  84. data/lib/tzinfo/definitions/America/Cancun.rb +104 -103
  85. data/lib/tzinfo/definitions/America/Caracas.rb +4 -4
  86. data/lib/tzinfo/definitions/America/Cayenne.rb +3 -3
  87. data/lib/tzinfo/definitions/America/Cayman.rb +3 -3
  88. data/lib/tzinfo/definitions/America/Chicago.rb +256 -255
  89. data/lib/tzinfo/definitions/America/Chihuahua.rb +109 -108
  90. data/lib/tzinfo/definitions/America/Coral_Harbour.rb +9 -9
  91. data/lib/tzinfo/definitions/America/Costa_Rica.rb +11 -11
  92. data/lib/tzinfo/definitions/America/Cuiaba.rb +145 -144
  93. data/lib/tzinfo/definitions/America/Curacao.rb +3 -3
  94. data/lib/tzinfo/definitions/America/Danmarkshavn.rb +35 -35
  95. data/lib/tzinfo/definitions/America/Dawson.rb +143 -142
  96. data/lib/tzinfo/definitions/America/Dawson_Creek.rb +59 -59
  97. data/lib/tzinfo/definitions/America/Denver.rb +178 -177
  98. data/lib/tzinfo/definitions/America/Detroit.rb +158 -157
  99. data/lib/tzinfo/definitions/America/Dominica.rb +2 -2
  100. data/lib/tzinfo/definitions/America/Edmonton.rb +170 -169
  101. data/lib/tzinfo/definitions/America/Eirunepe.rb +35 -35
  102. data/lib/tzinfo/definitions/America/El_Salvador.rb +6 -6
  103. data/lib/tzinfo/definitions/America/Fortaleza.rb +44 -44
  104. data/lib/tzinfo/definitions/America/Glace_Bay.rb +160 -159
  105. data/lib/tzinfo/definitions/America/Godthab.rb +134 -133
  106. data/lib/tzinfo/definitions/America/Goose_Bay.rb +225 -224
  107. data/lib/tzinfo/definitions/America/Grand_Turk.rb +137 -136
  108. data/lib/tzinfo/definitions/America/Grenada.rb +2 -2
  109. data/lib/tzinfo/definitions/America/Guadeloupe.rb +2 -2
  110. data/lib/tzinfo/definitions/America/Guatemala.rb +8 -8
  111. data/lib/tzinfo/definitions/America/Guayaquil.rb +3 -3
  112. data/lib/tzinfo/definitions/America/Guyana.rb +5 -5
  113. data/lib/tzinfo/definitions/America/Halifax.rb +248 -247
  114. data/lib/tzinfo/definitions/America/Havana.rb +175 -174
  115. data/lib/tzinfo/definitions/America/Hermosillo.rb +17 -17
  116. data/lib/tzinfo/definitions/America/Indiana/Indianapolis.rb +121 -120
  117. data/lib/tzinfo/definitions/America/Indiana/Knox.rb +172 -171
  118. data/lib/tzinfo/definitions/America/Indiana/Marengo.rb +123 -122
  119. data/lib/tzinfo/definitions/America/Indiana/Vevay.rb +100 -99
  120. data/lib/tzinfo/definitions/America/Inuvik.rb +143 -142
  121. data/lib/tzinfo/definitions/America/Iqaluit.rb +142 -141
  122. data/lib/tzinfo/definitions/America/Jamaica.rb +23 -23
  123. data/lib/tzinfo/definitions/America/Juneau.rb +163 -162
  124. data/lib/tzinfo/definitions/America/Kentucky/Louisville.rb +198 -197
  125. data/lib/tzinfo/definitions/America/Kentucky/Monticello.rb +166 -165
  126. data/lib/tzinfo/definitions/America/La_Paz.rb +4 -4
  127. data/lib/tzinfo/definitions/America/Lima.rb +17 -17
  128. data/lib/tzinfo/definitions/America/Los_Angeles.rb +204 -203
  129. data/lib/tzinfo/definitions/America/Maceio.rb +48 -48
  130. data/lib/tzinfo/definitions/America/Managua.rb +15 -15
  131. data/lib/tzinfo/definitions/America/Manaus.rb +35 -35
  132. data/lib/tzinfo/definitions/America/Martinique.rb +5 -5
  133. data/lib/tzinfo/definitions/America/Mazatlan.rb +110 -109
  134. data/lib/tzinfo/definitions/America/Menominee.rb +160 -159
  135. data/lib/tzinfo/definitions/America/Merida.rb +104 -103
  136. data/lib/tzinfo/definitions/America/Mexico_City.rb +116 -115
  137. data/lib/tzinfo/definitions/America/Miquelon.rb +122 -121
  138. data/lib/tzinfo/definitions/America/Monterrey.rb +106 -105
  139. data/lib/tzinfo/definitions/America/Montevideo.rb +69 -67
  140. data/lib/tzinfo/definitions/America/Montreal.rb +253 -252
  141. data/lib/tzinfo/definitions/America/Montserrat.rb +2 -2
  142. data/lib/tzinfo/definitions/America/Nassau.rb +166 -165
  143. data/lib/tzinfo/definitions/America/New_York.rb +256 -255
  144. data/lib/tzinfo/definitions/America/Nipigon.rb +151 -150
  145. data/lib/tzinfo/definitions/America/Nome.rb +164 -163
  146. data/lib/tzinfo/definitions/America/Noronha.rb +44 -44
  147. data/lib/tzinfo/definitions/America/North_Dakota/Center.rb +166 -165
  148. data/lib/tzinfo/definitions/America/Panama.rb +3 -3
  149. data/lib/tzinfo/definitions/America/Pangnirtung.rb +142 -141
  150. data/lib/tzinfo/definitions/America/Paramaribo.rb +6 -6
  151. data/lib/tzinfo/definitions/America/Phoenix.rb +14 -14
  152. data/lib/tzinfo/definitions/America/Port__m__au__m__Prince.rb +35 -35
  153. data/lib/tzinfo/definitions/America/Port_of_Spain.rb +2 -2
  154. data/lib/tzinfo/definitions/America/Porto_Velho.rb +31 -31
  155. data/lib/tzinfo/definitions/America/Puerto_Rico.rb +4 -4
  156. data/lib/tzinfo/definitions/America/Rainy_River.rb +151 -150
  157. data/lib/tzinfo/definitions/America/Rankin_Inlet.rb +142 -141
  158. data/lib/tzinfo/definitions/America/Recife.rb +44 -44
  159. data/lib/tzinfo/definitions/America/Regina.rb +53 -53
  160. data/lib/tzinfo/definitions/America/Rio_Branco.rb +31 -31
  161. data/lib/tzinfo/definitions/America/Santiago.rb +175 -174
  162. data/lib/tzinfo/definitions/America/Santo_Domingo.rb +18 -18
  163. data/lib/tzinfo/definitions/America/Sao_Paulo.rb +146 -145
  164. data/lib/tzinfo/definitions/America/Scoresbysund.rb +134 -133
  165. data/lib/tzinfo/definitions/America/St_Johns.rb +259 -258
  166. data/lib/tzinfo/definitions/America/St_Kitts.rb +2 -2
  167. data/lib/tzinfo/definitions/America/St_Lucia.rb +3 -3
  168. data/lib/tzinfo/definitions/America/St_Thomas.rb +2 -2
  169. data/lib/tzinfo/definitions/America/St_Vincent.rb +3 -3
  170. data/lib/tzinfo/definitions/America/Swift_Current.rb +23 -23
  171. data/lib/tzinfo/definitions/America/Tegucigalpa.rb +6 -6
  172. data/lib/tzinfo/definitions/America/Thule.rb +112 -111
  173. data/lib/tzinfo/definitions/America/Thunder_Bay.rb +159 -158
  174. data/lib/tzinfo/definitions/America/Tijuana.rb +171 -170
  175. data/lib/tzinfo/definitions/America/Toronto.rb +252 -251
  176. data/lib/tzinfo/definitions/America/Tortola.rb +2 -2
  177. data/lib/tzinfo/definitions/America/Vancouver.rb +206 -205
  178. data/lib/tzinfo/definitions/America/Whitehorse.rb +143 -142
  179. data/lib/tzinfo/definitions/America/Winnipeg.rb +202 -201
  180. data/lib/tzinfo/definitions/America/Yakutat.rb +163 -162
  181. data/lib/tzinfo/definitions/America/Yellowknife.rb +142 -141
  182. data/lib/tzinfo/definitions/Antarctica/Casey.rb +2 -2
  183. data/lib/tzinfo/definitions/Antarctica/Davis.rb +4 -4
  184. data/lib/tzinfo/definitions/Antarctica/DumontDUrville.rb +4 -4
  185. data/lib/tzinfo/definitions/Antarctica/Mawson.rb +2 -2
  186. data/lib/tzinfo/definitions/Antarctica/McMurdo.rb +145 -144
  187. data/lib/tzinfo/definitions/Antarctica/Palmer.rb +147 -146
  188. data/lib/tzinfo/definitions/Antarctica/Rothera.rb +2 -2
  189. data/lib/tzinfo/definitions/Antarctica/Syowa.rb +2 -2
  190. data/lib/tzinfo/definitions/Antarctica/Vostok.rb +2 -2
  191. data/lib/tzinfo/definitions/Asia/Aden.rb +2 -2
  192. data/lib/tzinfo/definitions/Asia/Almaty.rb +52 -52
  193. data/lib/tzinfo/definitions/Asia/Amman.rb +136 -135
  194. data/lib/tzinfo/definitions/Asia/Anadyr.rb +134 -133
  195. data/lib/tzinfo/definitions/Asia/Aqtau.rb +52 -52
  196. data/lib/tzinfo/definitions/Asia/Aqtobe.rb +52 -52
  197. data/lib/tzinfo/definitions/Asia/Ashgabat.rb +27 -27
  198. data/lib/tzinfo/definitions/Asia/Baghdad.rb +131 -130
  199. data/lib/tzinfo/definitions/Asia/Bahrain.rb +3 -3
  200. data/lib/tzinfo/definitions/Asia/Baku.rb +130 -129
  201. data/lib/tzinfo/definitions/Asia/Bangkok.rb +3 -3
  202. data/lib/tzinfo/definitions/Asia/Beirut.rb +158 -157
  203. data/lib/tzinfo/definitions/Asia/Bishkek.rb +52 -131
  204. data/lib/tzinfo/definitions/Asia/Brunei.rb +3 -3
  205. data/lib/tzinfo/definitions/Asia/Calcutta.rb +6 -6
  206. data/lib/tzinfo/definitions/Asia/Choibalsan.rb +125 -124
  207. data/lib/tzinfo/definitions/Asia/Chongqing.rb +15 -15
  208. data/lib/tzinfo/definitions/Asia/Colombo.rb +8 -8
  209. data/lib/tzinfo/definitions/Asia/Damascus.rb +168 -167
  210. data/lib/tzinfo/definitions/Asia/Dhaka.rb +7 -7
  211. data/lib/tzinfo/definitions/Asia/Dili.rb +6 -6
  212. data/lib/tzinfo/definitions/Asia/Dubai.rb +2 -2
  213. data/lib/tzinfo/definitions/Asia/Dushanbe.rb +25 -25
  214. data/lib/tzinfo/definitions/Asia/Gaza.rb +162 -161
  215. data/lib/tzinfo/definitions/Asia/Harbin.rb +18 -18
  216. data/lib/tzinfo/definitions/Asia/Hong_Kong.rb +70 -70
  217. data/lib/tzinfo/definitions/Asia/Hovd.rb +125 -124
  218. data/lib/tzinfo/definitions/Asia/Irkutsk.rb +135 -134
  219. data/lib/tzinfo/definitions/Asia/Jakarta.rb +9 -9
  220. data/lib/tzinfo/definitions/Asia/Jayapura.rb +4 -4
  221. data/lib/tzinfo/definitions/Asia/Jerusalem.rb +144 -144
  222. data/lib/tzinfo/definitions/Asia/Kabul.rb +3 -3
  223. data/lib/tzinfo/definitions/Asia/Kamchatka.rb +134 -133
  224. data/lib/tzinfo/definitions/Asia/Karachi.rb +8 -8
  225. data/lib/tzinfo/definitions/Asia/Kashgar.rb +16 -16
  226. data/lib/tzinfo/definitions/Asia/Katmandu.rb +3 -3
  227. data/lib/tzinfo/definitions/Asia/Krasnoyarsk.rb +134 -133
  228. data/lib/tzinfo/definitions/Asia/Kuala_Lumpur.rb +9 -9
  229. data/lib/tzinfo/definitions/Asia/Kuching.rb +20 -20
  230. data/lib/tzinfo/definitions/Asia/Kuwait.rb +2 -2
  231. data/lib/tzinfo/definitions/Asia/Macau.rb +43 -43
  232. data/lib/tzinfo/definitions/Asia/Magadan.rb +134 -133
  233. data/lib/tzinfo/definitions/Asia/Makassar.rb +5 -5
  234. data/lib/tzinfo/definitions/Asia/Manila.rb +11 -11
  235. data/lib/tzinfo/definitions/Asia/Muscat.rb +2 -2
  236. data/lib/tzinfo/definitions/Asia/Nicosia.rb +145 -144
  237. data/lib/tzinfo/definitions/Asia/Novosibirsk.rb +135 -134
  238. data/lib/tzinfo/definitions/Asia/Omsk.rb +134 -133
  239. data/lib/tzinfo/definitions/Asia/Oral.rb +52 -52
  240. data/lib/tzinfo/definitions/Asia/Phnom_Penh.rb +5 -5
  241. data/lib/tzinfo/definitions/Asia/Pontianak.rb +9 -9
  242. data/lib/tzinfo/definitions/Asia/Pyongyang.rb +7 -7
  243. data/lib/tzinfo/definitions/Asia/Qatar.rb +3 -3
  244. data/lib/tzinfo/definitions/Asia/Qyzylorda.rb +53 -53
  245. data/lib/tzinfo/definitions/Asia/Rangoon.rb +5 -5
  246. data/lib/tzinfo/definitions/Asia/Riyadh.rb +2 -2
  247. data/lib/tzinfo/definitions/Asia/Saigon.rb +5 -5
  248. data/lib/tzinfo/definitions/Asia/Sakhalin.rb +135 -134
  249. data/lib/tzinfo/definitions/Asia/Samarkand.rb +30 -30
  250. data/lib/tzinfo/definitions/Asia/Seoul.rb +14 -14
  251. data/lib/tzinfo/definitions/Asia/Shanghai.rb +19 -19
  252. data/lib/tzinfo/definitions/Asia/Singapore.rb +10 -10
  253. data/lib/tzinfo/definitions/Asia/Taipei.rb +42 -42
  254. data/lib/tzinfo/definitions/Asia/Tashkent.rb +30 -30
  255. data/lib/tzinfo/definitions/Asia/Tbilisi.rb +137 -136
  256. data/lib/tzinfo/definitions/Asia/Tehran.rb +105 -105
  257. data/lib/tzinfo/definitions/Asia/Thimphu.rb +3 -3
  258. data/lib/tzinfo/definitions/Asia/Tokyo.rb +12 -12
  259. data/lib/tzinfo/definitions/Asia/Ulaanbaatar.rb +125 -124
  260. data/lib/tzinfo/definitions/Asia/Urumqi.rb +15 -15
  261. data/lib/tzinfo/definitions/Asia/Vientiane.rb +5 -5
  262. data/lib/tzinfo/definitions/Asia/Vladivostok.rb +134 -133
  263. data/lib/tzinfo/definitions/Asia/Yakutsk.rb +134 -133
  264. data/lib/tzinfo/definitions/Asia/Yekaterinburg.rb +134 -133
  265. data/lib/tzinfo/definitions/Asia/Yerevan.rb +133 -132
  266. data/lib/tzinfo/definitions/Atlantic/Azores.rb +238 -237
  267. data/lib/tzinfo/definitions/Atlantic/Bermuda.rb +146 -145
  268. data/lib/tzinfo/definitions/Atlantic/Canary.rb +136 -135
  269. data/lib/tzinfo/definitions/Atlantic/Cape_Verde.rb +5 -5
  270. data/lib/tzinfo/definitions/Atlantic/Faeroe.rb +133 -132
  271. data/lib/tzinfo/definitions/Atlantic/Madeira.rb +238 -237
  272. data/lib/tzinfo/definitions/Atlantic/Reykjavik.rb +66 -66
  273. data/lib/tzinfo/definitions/Atlantic/South_Georgia.rb +2 -2
  274. data/lib/tzinfo/definitions/Atlantic/St_Helena.rb +3 -3
  275. data/lib/tzinfo/definitions/Atlantic/Stanley.rb +141 -141
  276. data/lib/tzinfo/definitions/Australia/Adelaide.rb +161 -160
  277. data/lib/tzinfo/definitions/Australia/Brisbane.rb +19 -19
  278. data/lib/tzinfo/definitions/Australia/Broken_Hill.rb +163 -162
  279. data/lib/tzinfo/definitions/Australia/Currie.rb +161 -160
  280. data/lib/tzinfo/definitions/Australia/Darwin.rb +11 -11
  281. data/lib/tzinfo/definitions/Australia/Hobart.rb +169 -168
  282. data/lib/tzinfo/definitions/Australia/Lindeman.rb +24 -24
  283. data/lib/tzinfo/definitions/Australia/Lord_Howe.rb +132 -131
  284. data/lib/tzinfo/definitions/Australia/Melbourne.rb +160 -159
  285. data/lib/tzinfo/definitions/Australia/Perth.rb +15 -15
  286. data/lib/tzinfo/definitions/Australia/Sydney.rb +160 -159
  287. data/lib/tzinfo/definitions/CET.rb +151 -150
  288. data/lib/tzinfo/definitions/EET.rb +139 -138
  289. data/lib/tzinfo/definitions/Etc/GMT.rb +1 -1
  290. data/lib/tzinfo/definitions/Etc/GMT__m__1.rb +1 -1
  291. data/lib/tzinfo/definitions/Etc/GMT__m__10.rb +1 -1
  292. data/lib/tzinfo/definitions/Etc/GMT__m__11.rb +1 -1
  293. data/lib/tzinfo/definitions/Etc/GMT__m__12.rb +1 -1
  294. data/lib/tzinfo/definitions/Etc/GMT__m__13.rb +1 -1
  295. data/lib/tzinfo/definitions/Etc/GMT__m__14.rb +1 -1
  296. data/lib/tzinfo/definitions/Etc/GMT__m__2.rb +1 -1
  297. data/lib/tzinfo/definitions/Etc/GMT__m__3.rb +1 -1
  298. data/lib/tzinfo/definitions/Etc/GMT__m__4.rb +1 -1
  299. data/lib/tzinfo/definitions/Etc/GMT__m__5.rb +1 -1
  300. data/lib/tzinfo/definitions/Etc/GMT__m__6.rb +1 -1
  301. data/lib/tzinfo/definitions/Etc/GMT__m__7.rb +1 -1
  302. data/lib/tzinfo/definitions/Etc/GMT__m__8.rb +1 -1
  303. data/lib/tzinfo/definitions/Etc/GMT__m__9.rb +1 -1
  304. data/lib/tzinfo/definitions/Etc/GMT__p__1.rb +1 -1
  305. data/lib/tzinfo/definitions/Etc/GMT__p__10.rb +1 -1
  306. data/lib/tzinfo/definitions/Etc/GMT__p__11.rb +1 -1
  307. data/lib/tzinfo/definitions/Etc/GMT__p__12.rb +1 -1
  308. data/lib/tzinfo/definitions/Etc/GMT__p__2.rb +1 -1
  309. data/lib/tzinfo/definitions/Etc/GMT__p__3.rb +1 -1
  310. data/lib/tzinfo/definitions/Etc/GMT__p__4.rb +1 -1
  311. data/lib/tzinfo/definitions/Etc/GMT__p__5.rb +1 -1
  312. data/lib/tzinfo/definitions/Etc/GMT__p__6.rb +1 -1
  313. data/lib/tzinfo/definitions/Etc/GMT__p__7.rb +1 -1
  314. data/lib/tzinfo/definitions/Etc/GMT__p__8.rb +1 -1
  315. data/lib/tzinfo/definitions/Etc/GMT__p__9.rb +1 -1
  316. data/lib/tzinfo/definitions/Etc/UCT.rb +1 -1
  317. data/lib/tzinfo/definitions/Etc/UTC.rb +1 -1
  318. data/lib/tzinfo/definitions/Europe/Amsterdam.rb +197 -196
  319. data/lib/tzinfo/definitions/Europe/Andorra.rb +125 -124
  320. data/lib/tzinfo/definitions/Europe/Athens.rb +156 -155
  321. data/lib/tzinfo/definitions/Europe/Belgrade.rb +136 -135
  322. data/lib/tzinfo/definitions/Europe/Berlin.rb +161 -160
  323. data/lib/tzinfo/definitions/Europe/Brussels.rb +203 -202
  324. data/lib/tzinfo/definitions/Europe/Bucharest.rb +156 -155
  325. data/lib/tzinfo/definitions/Europe/Budapest.rb +170 -169
  326. data/lib/tzinfo/definitions/Europe/Chisinau.rb +159 -158
  327. data/lib/tzinfo/definitions/Europe/Copenhagen.rb +152 -151
  328. data/lib/tzinfo/definitions/Europe/Dublin.rb +246 -245
  329. data/lib/tzinfo/definitions/Europe/Gibraltar.rb +216 -215
  330. data/lib/tzinfo/definitions/Europe/Helsinki.rb +136 -135
  331. data/lib/tzinfo/definitions/Europe/Istanbul.rb +190 -189
  332. data/lib/tzinfo/definitions/Europe/Kaliningrad.rb +148 -147
  333. data/lib/tzinfo/definitions/Europe/Kiev.rb +138 -137
  334. data/lib/tzinfo/definitions/Europe/Lisbon.rb +239 -238
  335. data/lib/tzinfo/definitions/Europe/London.rb +260 -259
  336. data/lib/tzinfo/definitions/Europe/Luxembourg.rb +200 -199
  337. data/lib/tzinfo/definitions/Europe/Madrid.rb +182 -181
  338. data/lib/tzinfo/definitions/Europe/Malta.rb +187 -186
  339. data/lib/tzinfo/definitions/Europe/Minsk.rb +136 -135
  340. data/lib/tzinfo/definitions/Europe/Monaco.rb +203 -202
  341. data/lib/tzinfo/definitions/Europe/Moscow.rb +147 -146
  342. data/lib/tzinfo/definitions/Europe/Oslo.rb +158 -157
  343. data/lib/tzinfo/definitions/Europe/Paris.rb +201 -200
  344. data/lib/tzinfo/definitions/Europe/Prague.rb +159 -158
  345. data/lib/tzinfo/definitions/Europe/Riga.rb +145 -144
  346. data/lib/tzinfo/definitions/Europe/Rome.rb +189 -188
  347. data/lib/tzinfo/definitions/Europe/Samara.rb +134 -133
  348. data/lib/tzinfo/definitions/Europe/Simferopol.rb +140 -139
  349. data/lib/tzinfo/definitions/Europe/Sofia.rb +146 -145
  350. data/lib/tzinfo/definitions/Europe/Stockholm.rb +138 -137
  351. data/lib/tzinfo/definitions/Europe/Tallinn.rb +141 -140
  352. data/lib/tzinfo/definitions/Europe/Tirane.rb +151 -150
  353. data/lib/tzinfo/definitions/Europe/Uzhgorod.rb +142 -141
  354. data/lib/tzinfo/definitions/Europe/Vaduz.rb +133 -132
  355. data/lib/tzinfo/definitions/Europe/Vienna.rb +159 -158
  356. data/lib/tzinfo/definitions/Europe/Vilnius.rb +137 -136
  357. data/lib/tzinfo/definitions/Europe/Warsaw.rb +184 -183
  358. data/lib/tzinfo/definitions/Europe/Zaporozhye.rb +139 -138
  359. data/lib/tzinfo/definitions/Europe/Zurich.rb +140 -139
  360. data/lib/tzinfo/definitions/Indian/Antananarivo.rb +4 -4
  361. data/lib/tzinfo/definitions/Indian/Chagos.rb +3 -3
  362. data/lib/tzinfo/definitions/Indian/Christmas.rb +2 -2
  363. data/lib/tzinfo/definitions/Indian/Cocos.rb +2 -2
  364. data/lib/tzinfo/definitions/Indian/Comoro.rb +2 -2
  365. data/lib/tzinfo/definitions/Indian/Kerguelen.rb +2 -2
  366. data/lib/tzinfo/definitions/Indian/Mahe.rb +2 -2
  367. data/lib/tzinfo/definitions/Indian/Maldives.rb +3 -3
  368. data/lib/tzinfo/definitions/Indian/Mauritius.rb +2 -2
  369. data/lib/tzinfo/definitions/Indian/Mayotte.rb +2 -2
  370. data/lib/tzinfo/definitions/Indian/Reunion.rb +2 -2
  371. data/lib/tzinfo/definitions/MET.rb +151 -150
  372. data/lib/tzinfo/definitions/Pacific/Apia.rb +4 -4
  373. data/lib/tzinfo/definitions/Pacific/Auckland.rb +173 -172
  374. data/lib/tzinfo/definitions/Pacific/Chatham.rb +145 -144
  375. data/lib/tzinfo/definitions/Pacific/Easter.rb +163 -162
  376. data/lib/tzinfo/definitions/Pacific/Efate.rb +22 -22
  377. data/lib/tzinfo/definitions/Pacific/Enderbury.rb +4 -4
  378. data/lib/tzinfo/definitions/Pacific/Fakaofo.rb +2 -2
  379. data/lib/tzinfo/definitions/Pacific/Fiji.rb +6 -6
  380. data/lib/tzinfo/definitions/Pacific/Funafuti.rb +2 -2
  381. data/lib/tzinfo/definitions/Pacific/Galapagos.rb +3 -3
  382. data/lib/tzinfo/definitions/Pacific/Gambier.rb +2 -2
  383. data/lib/tzinfo/definitions/Pacific/Guadalcanal.rb +2 -2
  384. data/lib/tzinfo/definitions/Pacific/Guam.rb +4 -4
  385. data/lib/tzinfo/definitions/Pacific/Honolulu.rb +6 -6
  386. data/lib/tzinfo/definitions/Pacific/Johnston.rb +1 -1
  387. data/lib/tzinfo/definitions/Pacific/Kiritimati.rb +4 -4
  388. data/lib/tzinfo/definitions/Pacific/Kosrae.rb +4 -4
  389. data/lib/tzinfo/definitions/Pacific/Kwajalein.rb +4 -4
  390. data/lib/tzinfo/definitions/Pacific/Majuro.rb +3 -3
  391. data/lib/tzinfo/definitions/Pacific/Marquesas.rb +2 -2
  392. data/lib/tzinfo/definitions/Pacific/Midway.rb +6 -6
  393. data/lib/tzinfo/definitions/Pacific/Nauru.rb +5 -5
  394. data/lib/tzinfo/definitions/Pacific/Niue.rb +4 -4
  395. data/lib/tzinfo/definitions/Pacific/Norfolk.rb +3 -3
  396. data/lib/tzinfo/definitions/Pacific/Noumea.rb +8 -8
  397. data/lib/tzinfo/definitions/Pacific/Pago_Pago.rb +6 -6
  398. data/lib/tzinfo/definitions/Pacific/Palau.rb +2 -2
  399. data/lib/tzinfo/definitions/Pacific/Pitcairn.rb +3 -3
  400. data/lib/tzinfo/definitions/Pacific/Ponape.rb +2 -2
  401. data/lib/tzinfo/definitions/Pacific/Port_Moresby.rb +3 -3
  402. data/lib/tzinfo/definitions/Pacific/Rarotonga.rb +28 -28
  403. data/lib/tzinfo/definitions/Pacific/Saipan.rb +5 -5
  404. data/lib/tzinfo/definitions/Pacific/Tahiti.rb +2 -2
  405. data/lib/tzinfo/definitions/Pacific/Tarawa.rb +2 -2
  406. data/lib/tzinfo/definitions/Pacific/Tongatapu.rb +10 -10
  407. data/lib/tzinfo/definitions/Pacific/Truk.rb +2 -2
  408. data/lib/tzinfo/definitions/Pacific/Wake.rb +2 -2
  409. data/lib/tzinfo/definitions/Pacific/Wallis.rb +2 -2
  410. data/lib/tzinfo/definitions/WET.rb +139 -138
  411. data/lib/tzinfo/timezone.rb +170 -175
  412. data/lib/tzinfo/timezone_period.rb +175 -0
  413. data/lib/tzinfo/timezone_period_list.rb +225 -0
  414. data/lib/tzinfo/tzdataparser.rb +99 -26
  415. data/test/tc_timezone.rb +231 -1
  416. data/test/tc_timezone_london.rb +13 -6
  417. data/test/tc_timezone_melbourne.rb +13 -6
  418. data/test/tc_timezone_new_york.rb +13 -6
  419. data/test/tc_timezone_period.rb +1 -1
  420. data/test/tc_timezone_period_list.rb +288 -0
  421. metadata +14 -12
  422. data/lib/tzinfo/definitions/Asia/Riyadh87.rb +0 -349
  423. data/lib/tzinfo/definitions/Asia/Riyadh88.rb +0 -350
  424. data/lib/tzinfo/definitions/Asia/Riyadh89.rb +0 -350
  425. data/lib/tzinfo/definitions/Mideast/Riyadh87.rb +0 -11
  426. data/lib/tzinfo/definitions/Mideast/Riyadh88.rb +0 -11
  427. data/lib/tzinfo/definitions/Mideast/Riyadh89.rb +0 -11
@@ -4,6 +4,9 @@ require 'tzinfo/timezone'
4
4
 
5
5
  include TZInfo
6
6
 
7
+ class TCTimezoneBlockCalled < StandardError
8
+ end
9
+
7
10
  class TCTimezone < Test::Unit::TestCase
8
11
  def test_get_valid_1
9
12
  tz = Timezone.get('Europe/London')
@@ -67,8 +70,9 @@ class TCTimezone < Test::Unit::TestCase
67
70
  end
68
71
 
69
72
  def test_get_case
73
+ Timezone.get('Europe/Prague')
70
74
  assert_raise(InvalidTimezoneIdentifier) {
71
- Timezone.get('Europe/london')
75
+ Timezone.get('Europe/prague')
72
76
  }
73
77
  end
74
78
 
@@ -195,6 +199,129 @@ class TCTimezone < Test::Unit::TestCase
195
199
  assert_equal('UTC', Timezone.get('UTC').to_s)
196
200
  end
197
201
 
202
+ def test_period_for_utc
203
+ dt = DateTime.new(2005,2,18,16,24,23)
204
+ t = Time.utc(2005,2,18,16,24,23)
205
+
206
+ dt_period = Timezone.get('Europe/London').period_for_utc(dt)
207
+ t_period = Timezone.get('Europe/London').period_for_utc(t)
208
+
209
+ assert_equal(DateTime.new(2004,10,31,1,0,0), dt_period.utc_start)
210
+ assert_equal(DateTime.new(2005,3,27,1,0,0), dt_period.utc_end)
211
+
212
+ assert_equal(DateTime.new(2004,10,31,1,0,0), t_period.utc_start)
213
+ assert_equal(DateTime.new(2005,3,27,1,0,0), t_period.utc_end)
214
+ end
215
+
216
+ def test_period_for_local
217
+ dt = DateTime.new(2005,2,18,16,24,23)
218
+ t = Time.utc(2005,2,18,16,24,23)
219
+
220
+ dt_period = Timezone.get('Europe/London').period_for_local(dt)
221
+ t_period = Timezone.get('Europe/London').period_for_local(t)
222
+
223
+ assert_equal(DateTime.new(2004,10,31,1,0,0), dt_period.utc_start)
224
+ assert_equal(DateTime.new(2005,3,27,1,0,0), dt_period.utc_end)
225
+
226
+ assert_equal(DateTime.new(2004,10,31,1,0,0), t_period.utc_start)
227
+ assert_equal(DateTime.new(2005,3,27,1,0,0), t_period.utc_end)
228
+ end
229
+
230
+ def test_period_for_local_invalid
231
+ assert_raise(PeriodNotFound) {
232
+ Timezone.get('America/New_York').period_for_local(DateTime.new(2004,4,4,2,30,0))
233
+ }
234
+ end
235
+
236
+ def test_period_for_local_ambiguous
237
+ assert_raise(AmbiguousTime) {
238
+ Timezone.get('America/New_York').period_for_local(DateTime.new(2004,10,31,1,30,0))
239
+ }
240
+ end
241
+
242
+ def test_period_for_local_dst_flag_resolved
243
+ dt = DateTime.new(2004,10,31,1,30,0)
244
+ tz = Timezone.get('America/New_York')
245
+
246
+ assert_period_for(DateTime.new(2004,4,4,7,0,0), DateTime.new(2004,10,31,6,0,0), true, tz.period_for_local(dt, true))
247
+ assert_period_for(DateTime.new(2004,10,31,6,0,0), DateTime.new(2005,4,3,7,0,0), false, tz.period_for_local(dt, false))
248
+ assert_period_for(DateTime.new(2004,4,4,7,0,0), DateTime.new(2004,10,31,6,0,0), true, tz.period_for_local(dt, true) {|periods| raise TCTimezoneBlockCalled, 'should not be called' })
249
+ assert_period_for(DateTime.new(2004,10,31,6,0,0), DateTime.new(2005,4,3,7,0,0), false, tz.period_for_local(dt, false) {|periods| raise TCTimezoneBlockCalled, 'should not be called' })
250
+ end
251
+
252
+ def test_period_for_local_dst_block_called
253
+ dt = DateTime.new(2004,10,31,1,30,0)
254
+ tz = Timezone.get('America/New_York')
255
+
256
+ assert_raise(TCTimezoneBlockCalled) {
257
+ tz.period_for_local(dt) {|periods|
258
+ assert_equal(2, periods.size)
259
+ assert_period_for(DateTime.new(2004,4,4,7,0,0), DateTime.new(2004,10,31,6,0,0), true, periods[0])
260
+ assert_period_for(DateTime.new(2004,10,31,6,0,0), DateTime.new(2005,4,3,7,0,0), false, periods[1])
261
+
262
+ # raise exception to test that the block was called
263
+ raise TCTimezoneBlockCalled, 'should be raised'
264
+ }
265
+ }
266
+
267
+ assert_period_for(DateTime.new(2004,4,4,7,0,0), DateTime.new(2004,10,31,6,0,0), true, tz.period_for_local(dt) {|periods| periods.first})
268
+ assert_period_for(DateTime.new(2004,10,31,6,0,0), DateTime.new(2005,4,3,7,0,0), false, tz.period_for_local(dt) {|periods| periods.last})
269
+ assert_period_for(DateTime.new(2004,4,4,7,0,0), DateTime.new(2004,10,31,6,0,0), true, tz.period_for_local(dt) {|periods| [periods.first]})
270
+ assert_period_for(DateTime.new(2004,10,31,6,0,0), DateTime.new(2005,4,3,7,0,0), false, tz.period_for_local(dt) {|periods| [periods.last]})
271
+ end
272
+
273
+ def test_period_for_local_dst_cannot_resolve
274
+ # At midnight local time on Aug 5 1915 in Warsaw, the clocks were put back
275
+ # 24 minutes and both periods were non-DST. Hence the block should be
276
+ # called regardless of the value of the Boolean dst parameter.
277
+
278
+ dt = DateTime.new(1915,8,4,23,40,0)
279
+ tz = Timezone.get('Europe/Warsaw')
280
+
281
+ assert_raise(TCTimezoneBlockCalled) {
282
+ tz.period_for_local(dt, true) {|periods|
283
+ assert_equal(2, periods.size)
284
+ assert_equal(DateTime.new(1915,8,4,22,36,0), periods[0].utc_end)
285
+ assert_equal(false, periods[0].dst?)
286
+ assert_period_for(DateTime.new(1915,8,4,22,36,0), DateTime.new(1916,4,30,22,0,0), false, periods[1])
287
+
288
+ raise TCTimezoneBlockCalled, 'should be raised'
289
+ }
290
+ }
291
+
292
+ assert_raise(TCTimezoneBlockCalled) {
293
+ tz.period_for_local(dt, false) {|periods|
294
+ assert_equal(2, periods.size)
295
+ assert_equal(DateTime.new(1915,8,4,22,36,0), periods[0].utc_end)
296
+ assert_equal(false, periods[0].dst?)
297
+ assert_period_for(DateTime.new(1915,8,4,22,36,0), DateTime.new(1916,4,30,22,0,0), false, periods[1])
298
+
299
+ raise TCTimezoneBlockCalled, 'should be raised'
300
+ }
301
+ }
302
+ end
303
+
304
+ def test_period_for_local_block_ambiguous
305
+ dt = DateTime.new(2004,10,31,1,30,0)
306
+ tz = Timezone.get('America/New_York')
307
+
308
+ assert_raise(AmbiguousTime) {
309
+ tz.period_for_local(dt) {|periods| nil}
310
+ }
311
+
312
+ assert_raise(AmbiguousTime) {
313
+ tz.period_for_local(dt) {|periods| periods}
314
+ }
315
+
316
+ assert_raise(AmbiguousTime) {
317
+ tz.period_for_local(dt) {|periods| []}
318
+ }
319
+
320
+ assert_raise(AmbiguousTime) {
321
+ tz.period_for_local(dt) {|periods| raise AmbiguousTime, 'Ambiguous time'}
322
+ }
323
+ end
324
+
198
325
  def test_utc_to_local
199
326
  dt = DateTime.new(2005,2,18,16,24,23)
200
327
  t = Time.utc(2005,2,18,16,24,23)
@@ -215,6 +342,102 @@ class TCTimezone < Test::Unit::TestCase
215
342
  assert_not_equal(dt, Timezone.get('Europe/London').local_to_utc(t))
216
343
  end
217
344
 
345
+ def test_local_to_utc_invalid
346
+ assert_raise(PeriodNotFound) {
347
+ Timezone.get('America/New_York').local_to_utc(DateTime.new(2004,4,4,2,30,0))
348
+ }
349
+ end
350
+
351
+ def test_local_to_utc_ambiguous
352
+ assert_raise(AmbiguousTime) {
353
+ Timezone.get('America/New_York').local_to_utc(DateTime.new(2004,10,31,1,30,0))
354
+ }
355
+ end
356
+
357
+ def test_local_to_utc_dst_flag_resolved
358
+ dt = DateTime.new(2004,10,31,1,30,0)
359
+ tz = Timezone.get('America/New_York')
360
+
361
+ assert_equal(DateTime.new(2004,10,31,5,30,0), tz.local_to_utc(dt, true))
362
+ assert_equal(DateTime.new(2004,10,31,6,30,0), tz.local_to_utc(dt, false))
363
+ assert_equal(DateTime.new(2004,10,31,5,30,0), tz.local_to_utc(dt, true) {|periods| raise TCTimezoneBlockCalled, 'should not be called' })
364
+ assert_equal(DateTime.new(2004,10,31,6,30,0), tz.local_to_utc(dt, false) {|periods| raise TCTimezoneBlockCalled, 'should not be called' })
365
+ end
366
+
367
+ def test_local_to_utc_dst_block_called
368
+ dt = DateTime.new(2004,10,31,1,30,0)
369
+ tz = Timezone.get('America/New_York')
370
+
371
+ assert_raise(TCTimezoneBlockCalled) {
372
+ tz.local_to_utc(dt) {|periods|
373
+ assert_equal(2, periods.size)
374
+ assert_period_for(DateTime.new(2004,4,4,7,0,0), DateTime.new(2004,10,31,6,0,0), true, periods[0])
375
+ assert_period_for(DateTime.new(2004,10,31,6,0,0), DateTime.new(2005,4,3,7,0,0), false, periods[1])
376
+
377
+ # raise exception to test that the block was called
378
+ raise TCTimezoneBlockCalled, 'should be raised'
379
+ }
380
+ }
381
+
382
+ assert_equal(DateTime.new(2004,10,31,5,30,0), tz.local_to_utc(dt) {|periods| periods.first})
383
+ assert_equal(DateTime.new(2004,10,31,6,30,0), tz.local_to_utc(dt) {|periods| periods.last})
384
+ end
385
+
386
+ def test_local_to_utc_dst_cannot_resolve
387
+ # At midnight local time on Aug 5 1915 in Warsaw, the clocks were put back
388
+ # 24 minutes and both periods were non-DST. Hence the block should be
389
+ # called regardless of the value of the Boolean dst parameter.
390
+
391
+ dt = DateTime.new(1915,8,4,23,40,0)
392
+ tz = Timezone.get('Europe/Warsaw')
393
+
394
+ assert_raise(TCTimezoneBlockCalled) {
395
+ tz.local_to_utc(dt, true) {|periods|
396
+ assert_equal(2, periods.size)
397
+ assert_equal(DateTime.new(1915,8,4,22,36,0), periods[0].utc_end)
398
+ assert_equal(false, periods[0].dst?)
399
+ assert_period_for(DateTime.new(1915,8,4,22,36,0), DateTime.new(1916,4,30,22,0,0), false, periods[1])
400
+
401
+ raise TCTimezoneBlockCalled, 'should be raised'
402
+ }
403
+ }
404
+
405
+ assert_raise(TCTimezoneBlockCalled) {
406
+ tz.local_to_utc(dt, false) {|periods|
407
+ assert_equal(2, periods.size)
408
+ assert_equal(DateTime.new(1915,8,4,22,36,0), periods[0].utc_end)
409
+ assert_equal(false, periods[0].dst?)
410
+ assert_period_for(DateTime.new(1915,8,4,22,36,0), DateTime.new(1916,4,30,22,0,0), false, periods[1])
411
+
412
+ raise TCTimezoneBlockCalled, 'should be raised'
413
+ }
414
+ }
415
+
416
+ assert_equal(DateTime.new(1915,8,4,22,16,0), tz.local_to_utc(dt) {|periods| periods.first})
417
+ assert_equal(DateTime.new(1915,8,4,22,40,0), tz.local_to_utc(dt) {|periods| periods.last})
418
+ end
419
+
420
+ def test_local_to_utc_block_ambiguous
421
+ dt = DateTime.new(2004,10,31,1,30,0)
422
+ tz = Timezone.get('America/New_York')
423
+
424
+ assert_raise(AmbiguousTime) {
425
+ tz.local_to_utc(dt) {|periods| nil}
426
+ }
427
+
428
+ assert_raise(AmbiguousTime) {
429
+ tz.local_to_utc(dt) {|periods| periods}
430
+ }
431
+
432
+ assert_raise(AmbiguousTime) {
433
+ tz.local_to_utc(dt) {|periods| []}
434
+ }
435
+
436
+ assert_raise(AmbiguousTime) {
437
+ tz.local_to_utc(dt) {|periods| raise AmbiguousTime, 'Ambiguous time'}
438
+ }
439
+ end
440
+
218
441
  def test_now
219
442
  assert_kind_of(Time, Timezone.get('Europe/London').now)
220
443
  end
@@ -259,4 +482,11 @@ class TCTimezone < Test::Unit::TestCase
259
482
  assert((Timezone.get('America/New_York') <=> Timezone.get('Europe/Paris')) < 0)
260
483
  assert((Timezone.get('Europe/Paris') <=> Timezone.get('America/New_York')) > 0)
261
484
  end
485
+
486
+ private
487
+ def assert_period_for(utc_start, utc_end, dst, period)
488
+ assert_equal(utc_start, period.utc_start)
489
+ assert_equal(utc_end, period.utc_end)
490
+ assert_equal(dst, period.dst?)
491
+ end
262
492
  end
@@ -19,10 +19,13 @@ class TCTimezoneLondon < Test::Unit::TestCase
19
19
 
20
20
  assert_equal(DateTime.new(2004,3,28,0,59,59), tz.local_to_utc(DateTime.new(2004,3,28,0,59,59)))
21
21
  assert_equal(DateTime.new(2004,3,28,1,0,0), tz.local_to_utc(DateTime.new(2004,3,28,2,0,0)))
22
- assert_equal(DateTime.new(2004,10,31,0,59,59), tz.local_to_utc(DateTime.new(2004,10,31,1,59,59)))
23
- assert_equal(DateTime.new(2004,10,31,0,0,0), tz.local_to_utc(DateTime.new(2004,10,31,1,0,0))) # returns first possible utc time
22
+ assert_equal(DateTime.new(2004,10,31,0,59,59), tz.local_to_utc(DateTime.new(2004,10,31,1,59,59), true))
23
+ assert_equal(DateTime.new(2004,10,31,1,59,59), tz.local_to_utc(DateTime.new(2004,10,31,1,59,59), false))
24
+ assert_equal(DateTime.new(2004,10,31,0,0,0), tz.local_to_utc(DateTime.new(2004,10,31,1,0,0), true))
25
+ assert_equal(DateTime.new(2004,10,31,1,0,0), tz.local_to_utc(DateTime.new(2004,10,31,1,0,0), false))
24
26
 
25
27
  assert_raise(PeriodNotFound) { tz.local_to_utc(DateTime.new(2004,3,28,1,0,0)) }
28
+ assert_raise(AmbiguousTime) { tz.local_to_utc(DateTime.new(2004,10,31,1,0,0)) }
26
29
 
27
30
  assert_equal(:GMT, tz.period_for_utc(DateTime.new(2004,3,28,0,59,59)).zone_identifier)
28
31
  assert_equal(:BST, tz.period_for_utc(DateTime.new(2004,3,28,1,0,0)).zone_identifier)
@@ -31,8 +34,10 @@ class TCTimezoneLondon < Test::Unit::TestCase
31
34
 
32
35
  assert_equal(:GMT, tz.period_for_local(DateTime.new(2004,3,28,0,59,59)).zone_identifier)
33
36
  assert_equal(:BST, tz.period_for_local(DateTime.new(2004,3,28,2,0,0)).zone_identifier)
34
- assert_equal(:BST, tz.period_for_local(DateTime.new(2004,10,31,1,59,59)).zone_identifier)
35
- assert_equal(:BST, tz.period_for_local(DateTime.new(2004,10,31,1,0,0)).zone_identifier)
37
+ assert_equal(:BST, tz.period_for_local(DateTime.new(2004,10,31,1,59,59), true).zone_identifier)
38
+ assert_equal(:GMT, tz.period_for_local(DateTime.new(2004,10,31,1,59,59), false).zone_identifier)
39
+ assert_equal(:BST, tz.period_for_local(DateTime.new(2004,10,31,1,0,0), true).zone_identifier)
40
+ assert_equal(:GMT, tz.period_for_local(DateTime.new(2004,10,31,1,0,0), false).zone_identifier)
36
41
 
37
42
  assert_equal(0, tz.period_for_utc(DateTime.new(2004,3,28,0,59,59)).utc_total_offset)
38
43
  assert_equal(3600, tz.period_for_utc(DateTime.new(2004,3,28,1,0,0)).utc_total_offset)
@@ -41,7 +46,9 @@ class TCTimezoneLondon < Test::Unit::TestCase
41
46
 
42
47
  assert_equal(0, tz.period_for_local(DateTime.new(2004,3,28,0,59,59)).utc_total_offset)
43
48
  assert_equal(3600, tz.period_for_local(DateTime.new(2004,3,28,2,0,0)).utc_total_offset)
44
- assert_equal(3600, tz.period_for_local(DateTime.new(2004,10,31,1,59,59)).utc_total_offset)
45
- assert_equal(3600, tz.period_for_local(DateTime.new(2004,10,31,1,0,0)).utc_total_offset)
49
+ assert_equal(3600, tz.period_for_local(DateTime.new(2004,10,31,1,59,59), true).utc_total_offset)
50
+ assert_equal(0, tz.period_for_local(DateTime.new(2004,10,31,1,59,59), false).utc_total_offset)
51
+ assert_equal(3600, tz.period_for_local(DateTime.new(2004,10,31,1,0,0), true).utc_total_offset)
52
+ assert_equal(0, tz.period_for_local(DateTime.new(2004,10,31,1,0,0), false).utc_total_offset)
46
53
  end
47
54
  end
@@ -17,20 +17,25 @@ class TCTimezoneMelbourne < Test::Unit::TestCase
17
17
  assert_equal(DateTime.new(2004,10,31,1,59,59), tz.utc_to_local(DateTime.new(2004,10,30,15,59,59)))
18
18
  assert_equal(DateTime.new(2004,10,31,3,0,0), tz.utc_to_local(DateTime.new(2004,10,30,16,0,0)))
19
19
 
20
- assert_equal(DateTime.new(2004,3,27,15,59,59), tz.local_to_utc(DateTime.new(2004,3,28,2,59,59)))
21
- assert_equal(DateTime.new(2004,3,27,15,0,0), tz.local_to_utc(DateTime.new(2004,3,28,2,0,0))) # returns first possible utc time
20
+ assert_equal(DateTime.new(2004,3,27,15,59,59), tz.local_to_utc(DateTime.new(2004,3,28,2,59,59), true))
21
+ assert_equal(DateTime.new(2004,3,27,16,59,59), tz.local_to_utc(DateTime.new(2004,3,28,2,59,59), false))
22
+ assert_equal(DateTime.new(2004,3,27,15,0,0), tz.local_to_utc(DateTime.new(2004,3,28,2,0,0), true))
23
+ assert_equal(DateTime.new(2004,3,27,16,0,0), tz.local_to_utc(DateTime.new(2004,3,28,2,0,0), false))
22
24
  assert_equal(DateTime.new(2004,10,30,15,59,59), tz.local_to_utc(DateTime.new(2004,10,31,1,59,59)))
23
25
  assert_equal(DateTime.new(2004,10,30,16,0,0), tz.local_to_utc(DateTime.new(2004,10,31,3,0,0)))
24
26
 
25
27
  assert_raise(PeriodNotFound) { tz.local_to_utc(DateTime.new(2004,10,31,2,0,0)) }
28
+ assert_raise(AmbiguousTime) { tz.local_to_utc(DateTime.new(2004,3,28,2,0,0)) }
26
29
 
27
30
  assert_equal(:EST, tz.period_for_utc(DateTime.new(2004,3,27,15,59,59)).zone_identifier)
28
31
  assert_equal(:EST, tz.period_for_utc(DateTime.new(2004,3,27,16,0,0)).zone_identifier)
29
32
  assert_equal(:EST, tz.period_for_utc(DateTime.new(2004,10,30,15,59,59)).zone_identifier)
30
33
  assert_equal(:EST, tz.period_for_utc(DateTime.new(2004,10,30,16,0,0)).zone_identifier)
31
34
 
32
- assert_equal(:EST, tz.period_for_local(DateTime.new(2004,3,28,2,59,59)).zone_identifier)
33
- assert_equal(:EST, tz.period_for_local(DateTime.new(2004,3,28,2,0,0)).zone_identifier)
35
+ assert_equal(:EST, tz.period_for_local(DateTime.new(2004,3,28,2,59,59), true).zone_identifier)
36
+ assert_equal(:EST, tz.period_for_local(DateTime.new(2004,3,28,2,59,59), false).zone_identifier)
37
+ assert_equal(:EST, tz.period_for_local(DateTime.new(2004,3,28,2,0,0), true).zone_identifier)
38
+ assert_equal(:EST, tz.period_for_local(DateTime.new(2004,3,28,2,0,0), false).zone_identifier)
34
39
  assert_equal(:EST, tz.period_for_local(DateTime.new(2004,10,31,1,59,59)).zone_identifier)
35
40
  assert_equal(:EST, tz.period_for_local(DateTime.new(2004,10,31,3,0,0)).zone_identifier)
36
41
 
@@ -39,8 +44,10 @@ class TCTimezoneMelbourne < Test::Unit::TestCase
39
44
  assert_equal(36000, tz.period_for_utc(DateTime.new(2004,10,30,15,59,59)).utc_total_offset)
40
45
  assert_equal(39600, tz.period_for_utc(DateTime.new(2004,10,30,16,0,0)).utc_total_offset)
41
46
 
42
- assert_equal(39600, tz.period_for_local(DateTime.new(2004,3,28,2,59,59)).utc_total_offset)
43
- assert_equal(39600, tz.period_for_local(DateTime.new(2004,3,28,2,0,0)).utc_total_offset)
47
+ assert_equal(39600, tz.period_for_local(DateTime.new(2004,3,28,2,59,59), true).utc_total_offset)
48
+ assert_equal(36000, tz.period_for_local(DateTime.new(2004,3,28,2,59,59), false).utc_total_offset)
49
+ assert_equal(39600, tz.period_for_local(DateTime.new(2004,3,28,2,0,0), true).utc_total_offset)
50
+ assert_equal(36000, tz.period_for_local(DateTime.new(2004,3,28,2,0,0), false).utc_total_offset)
44
51
  assert_equal(36000, tz.period_for_local(DateTime.new(2004,10,31,1,59,59)).utc_total_offset)
45
52
  assert_equal(39600, tz.period_for_local(DateTime.new(2004,10,31,3,0,0)).utc_total_offset)
46
53
  end
@@ -19,10 +19,13 @@ class TCTimezoneNewYork < Test::Unit::TestCase
19
19
 
20
20
  assert_equal(DateTime.new(2004,4,4,6,59,59), tz.local_to_utc(DateTime.new(2004,4,4,1,59,59)))
21
21
  assert_equal(DateTime.new(2004,4,4,7,0,0), tz.local_to_utc(DateTime.new(2004,4,4,3,0,0)))
22
- assert_equal(DateTime.new(2004,10,31,5,59,59), tz.local_to_utc(DateTime.new(2004,10,31,1,59,59)))
23
- assert_equal(DateTime.new(2004,10,31,5,0,0), tz.local_to_utc(DateTime.new(2004,10,31,1,0,0))) # returns first possible utc time
22
+ assert_equal(DateTime.new(2004,10,31,5,59,59), tz.local_to_utc(DateTime.new(2004,10,31,1,59,59), true))
23
+ assert_equal(DateTime.new(2004,10,31,6,59,59), tz.local_to_utc(DateTime.new(2004,10,31,1,59,59), false))
24
+ assert_equal(DateTime.new(2004,10,31,5,0,0), tz.local_to_utc(DateTime.new(2004,10,31,1,0,0), true))
25
+ assert_equal(DateTime.new(2004,10,31,6,0,0), tz.local_to_utc(DateTime.new(2004,10,31,1,0,0), false))
24
26
 
25
27
  assert_raise(PeriodNotFound) { tz.local_to_utc(DateTime.new(2004,4,4,2,0,0)) }
28
+ assert_raise(AmbiguousTime) { tz.local_to_utc(DateTime.new(2004,10,31,1,0,0)) }
26
29
 
27
30
  assert_equal(:EST, tz.period_for_utc(DateTime.new(2004,4,4,6,59,59)).zone_identifier)
28
31
  assert_equal(:EDT, tz.period_for_utc(DateTime.new(2004,4,4,7,0,0)).zone_identifier)
@@ -31,8 +34,10 @@ class TCTimezoneNewYork < Test::Unit::TestCase
31
34
 
32
35
  assert_equal(:EST, tz.period_for_local(DateTime.new(2004,4,4,1,59,59)).zone_identifier)
33
36
  assert_equal(:EDT, tz.period_for_local(DateTime.new(2004,4,4,3,0,0)).zone_identifier)
34
- assert_equal(:EDT, tz.period_for_local(DateTime.new(2004,10,31,1,59,59)).zone_identifier)
35
- assert_equal(:EDT, tz.period_for_local(DateTime.new(2004,10,31,1,0,0)).zone_identifier)
37
+ assert_equal(:EDT, tz.period_for_local(DateTime.new(2004,10,31,1,59,59), true).zone_identifier)
38
+ assert_equal(:EST, tz.period_for_local(DateTime.new(2004,10,31,1,59,59), false).zone_identifier)
39
+ assert_equal(:EDT, tz.period_for_local(DateTime.new(2004,10,31,1,0,0), true).zone_identifier)
40
+ assert_equal(:EST, tz.period_for_local(DateTime.new(2004,10,31,1,0,0), false).zone_identifier)
36
41
 
37
42
  assert_equal(-18000, tz.period_for_utc(DateTime.new(2004,4,4,6,59,59)).utc_total_offset)
38
43
  assert_equal(-14400, tz.period_for_utc(DateTime.new(2004,4,4,7,0,0)).utc_total_offset)
@@ -41,7 +46,9 @@ class TCTimezoneNewYork < Test::Unit::TestCase
41
46
 
42
47
  assert_equal(-18000, tz.period_for_local(DateTime.new(2004,4,4,1,59,59)).utc_total_offset)
43
48
  assert_equal(-14400, tz.period_for_local(DateTime.new(2004,4,4,3,0,0)).utc_total_offset)
44
- assert_equal(-14400, tz.period_for_local(DateTime.new(2004,10,31,1,59,59)).utc_total_offset)
45
- assert_equal(-14400, tz.period_for_local(DateTime.new(2004,10,31,1,0,0)).utc_total_offset)
49
+ assert_equal(-14400, tz.period_for_local(DateTime.new(2004,10,31,1,59,59), true).utc_total_offset)
50
+ assert_equal(-18000, tz.period_for_local(DateTime.new(2004,10,31,1,59,59), false).utc_total_offset)
51
+ assert_equal(-14400, tz.period_for_local(DateTime.new(2004,10,31,1,0,0), true).utc_total_offset)
52
+ assert_equal(-18000, tz.period_for_local(DateTime.new(2004,10,31,1,0,0), false).utc_total_offset)
46
53
  end
47
54
  end
@@ -1,6 +1,6 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
2
  require 'test/unit'
3
- require 'tzinfo/timezone'
3
+ require 'tzinfo/timezone_period'
4
4
 
5
5
  include TZInfo
6
6
 
@@ -0,0 +1,288 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'test/unit'
3
+ require 'tzinfo/timezone_period_list'
4
+
5
+ include TZInfo
6
+
7
+ class TCTimezonePeriod < Test::Unit::TestCase
8
+ def test_add
9
+ # Just a test for no exception
10
+
11
+ list = TimezonePeriodList.new
12
+ list.add(2005, 1) { TimezonePeriod.new(DateTime.new(2005,1,1,1,0,0), DateTime.new(2005,3,1,1,0,0), 0, 0, :TEST) }
13
+ list.add(2005, 3) { TimezonePeriod.new(DateTime.new(2005,3,1,1,0,0), DateTime.new(2005,5,1,1,0,0), 0, 0, :TEST) }
14
+ list.add(2005, 5) { TimezonePeriod.new(DateTime.new(2005,5,1,1,0,0), DateTime.new(2005,5,2,1,0,0), 0, 0, :TEST) }
15
+ list.add(2005, 5) { TimezonePeriod.new(DateTime.new(2005,5,2,1,0,0), DateTime.new(2005,7,1,1,0,0), 0, 0, :TEST) }
16
+ end
17
+
18
+ def test_add_incorrect_order
19
+ list = TimezonePeriodList.new
20
+ list.add(2005, 1) { TimezonePeriod.new(DateTime.new(2005,1,1,1,0,0), DateTime.new(2005,2,1,1,0,0), 0, 0, :TEST) }
21
+ list.add(2005, 3) { TimezonePeriod.new(DateTime.new(2005,3,1,1,0,0), DateTime.new(2005,5,1,1,0,0), 0, 0, :TEST) }
22
+
23
+ assert_raise(ArgumentError) {
24
+ list.add(2005, 2) { TimezonePeriod.new(DateTime.new(2005,2,1,1,0,0), DateTime.new(2005,3,1,1,0,0), 0, 0, :TEST) }
25
+ }
26
+
27
+ assert_raise(ArgumentError) {
28
+ list.add(2004, 12) { TimezonePeriod.new(DateTime.new(2004,12,1,1,0,0), DateTime.new(2005,1,1,1,0,0), 0, 0, :TEST) }
29
+ }
30
+
31
+ assert_raise(ArgumentError) {
32
+ list.add_unbounded_start { TimezonePeriod.new(nil, DateTime.new(2005,1,1,1,0,0), 0, 0, :TEST) }
33
+ }
34
+ end
35
+
36
+ def test_add_incorrect_order_unbounded
37
+ list = TimezonePeriodList.new
38
+ list.add_unbounded_start { TimezonePeriod.new(nil, DateTime.new(2005,1,1,1,0,0), 0, 0, :TEST) }
39
+
40
+ assert_raise(ArgumentError) {
41
+ list.add_unbounded_start { TimezonePeriod.new(nil, DateTime.new(2005,1,1,1,0,0), 0, 0, :TEST) }
42
+ }
43
+ end
44
+
45
+ def test_period_for_utc
46
+ list = TimezonePeriodList.new
47
+ list.add(2000, 4) { TimezonePeriod.new(DateTime.new(2000,4,1,1,0,0),DateTime.new(2000,10,1,1,0,0),-18000,3600,:'TESTD') }
48
+ list.add(2000, 10) { TimezonePeriod.new(DateTime.new(2000,10,1,1,0,0),DateTime.new(2001,3,1,1,0,0),-18000,0,:'TESTS') }
49
+ list.add(2001, 3) { TimezonePeriod.new(DateTime.new(2001,3,1,1,0,0),DateTime.new(2001,4,1,1,0,0),-18000,3600,:'TESTD') }
50
+ list.add(2001, 4) { TimezonePeriod.new(DateTime.new(2001,4,1,1,0,0),DateTime.new(2001,10,1,1,0,0),-21600,3600,:'TESTD') }
51
+ list.add(2001, 10) { TimezonePeriod.new(DateTime.new(2001,10,1,1,0,0),DateTime.new(2002,10,1,1,0,0),-18000,0,:'TESTS') }
52
+ list.add(2002, 10) { TimezonePeriod.new(DateTime.new(2002,10,1,1,0,0),DateTime.new(2003,2,1,1,0,0),-18000,0,:'TESTS') }
53
+
54
+ # TimezonePeriodList expands out blocks and caches the results
55
+ # run twice to ensure this is being done correctly
56
+ 2.times {|i|
57
+ assert_raise(PeriodNotFound) {
58
+ list.period_for_utc(DateTime.new(1999,12,1,0,0,0))
59
+ }
60
+ assert_raise(PeriodNotFound) {
61
+ list.period_for_utc(DateTime.new(2000,4,1,0,59,59))
62
+ }
63
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2000,4,1,1,0,0),DateTime.new(2000,10,1,1,0,0),-18000,3600,:'TESTD'),
64
+ list.period_for_utc(DateTime.new(2000,4,1,1,0,0)))
65
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2000,4,1,1,0,0),DateTime.new(2000,10,1,1,0,0),-18000,3600,:'TESTD'),
66
+ list.period_for_utc(DateTime.new(2000,10,1,0,59,59)))
67
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2000,10,1,1,0,0),DateTime.new(2001,3,1,1,0,0),-18000,0,:'TESTS'),
68
+ list.period_for_utc(DateTime.new(2000,10,1,1,0,0)))
69
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2000,10,1,1,0,0),DateTime.new(2001,3,1,1,0,0),-18000,0,:'TESTS'),
70
+ list.period_for_utc(DateTime.new(2001,3,1,0,59,59)))
71
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2001,3,1,1,0,0),DateTime.new(2001,4,1,1,0,0),-18000,3600,:'TESTD'),
72
+ list.period_for_utc(DateTime.new(2001,3,1,1,0,0)))
73
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2001,3,1,1,0,0),DateTime.new(2001,4,1,1,0,0),-18000,3600,:'TESTD'),
74
+ list.period_for_utc(DateTime.new(2001,4,1,0,59,59)))
75
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2001,4,1,1,0,0),DateTime.new(2001,10,1,1,0,0),-21600,3600,:'TESTD'),
76
+ list.period_for_utc(DateTime.new(2001,4,1,1,0,0)))
77
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2001,4,1,1,0,0),DateTime.new(2001,10,1,1,0,0),-21600,3600,:'TESTD'),
78
+ list.period_for_utc(DateTime.new(2001,10,1,0,59,59)))
79
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2001,10,1,1,0,0),DateTime.new(2002,10,1,1,0,0),-18000,0,:'TESTS'),
80
+ list.period_for_utc(DateTime.new(2001,10,1,1,0,0)))
81
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2001,10,1,1,0,0),DateTime.new(2002,10,1,1,0,0),-18000,0,:'TESTS'),
82
+ list.period_for_utc(DateTime.new(2002,2,1,1,0,0)))
83
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2001,10,1,1,0,0),DateTime.new(2002,10,1,1,0,0),-18000,0,:'TESTS'),
84
+ list.period_for_utc(DateTime.new(2002,10,1,0,59,59)))
85
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2002,10,1,1,0,0),DateTime.new(2003,2,1,1,0,0),-18000,0,:'TESTS'),
86
+ list.period_for_utc(DateTime.new(2002,10,1,1,0,0)))
87
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2002,10,1,1,0,0),DateTime.new(2003,2,1,1,0,0),-18000,0,:'TESTS'),
88
+ list.period_for_utc(DateTime.new(2003,2,1,0,59,59)))
89
+
90
+ assert_raise(PeriodNotFound) {
91
+ list.period_for_utc(DateTime.new(2003,2,1,1,0,0))
92
+ }
93
+ assert_raise(PeriodNotFound) {
94
+ list.period_for_utc(DateTime.new(2004,1,1,1,0,0))
95
+ }
96
+ }
97
+ end
98
+
99
+ def test_period_for_utc_unbounded
100
+ list = TimezonePeriodList.new
101
+ list.add_unbounded_start { TimezonePeriod.new(nil,DateTime.new(2000,10,1,1,0,0),-18000,3600,:'TESTD') }
102
+ list.add(2000, 10) { TimezonePeriod.new(DateTime.new(2000,10,1,1,0,0),DateTime.new(2001,3,1,1,0,0),-18000,0,:'TESTS') }
103
+ list.add(2001, 3) { TimezonePeriod.new(DateTime.new(2001,3,1,1,0,0),nil,-18000,3600,:'TESTD') }
104
+
105
+ assert_period_equal(TimezonePeriod.new(nil,DateTime.new(2000,10,1,1,0,0),-18000,3600,:'TESTD'),
106
+ list.period_for_utc(DateTime.new(1999,12,1,1,0,0)))
107
+ assert_period_equal(TimezonePeriod.new(nil,DateTime.new(2000,10,1,1,0,0),-18000,3600,:'TESTD'),
108
+ list.period_for_utc(DateTime.new(2000,10,1,0,59,59)))
109
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2000,10,1,1,0,0),DateTime.new(2001,3,1,1,0,0),-18000,0,:'TESTS'),
110
+ list.period_for_utc(DateTime.new(2000,10,1,1,0,0)))
111
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2000,10,1,1,0,0),DateTime.new(2001,3,1,1,0,0),-18000,0,:'TESTS'),
112
+ list.period_for_utc(DateTime.new(2001,3,1,0,59,59)))
113
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2001,3,1,1,0,0),nil,-18000,3600,:'TESTD'),
114
+ list.period_for_utc(DateTime.new(2001,3,1,1,0,0)))
115
+ assert_period_equal(TimezonePeriod.new(DateTime.new(2001,3,1,1,0,0),nil,-18000,3600,:'TESTD'),
116
+ list.period_for_utc(DateTime.new(2002,1,1,1,0,0)))
117
+ end
118
+
119
+ def test_period_for_utc_gap
120
+ list = TimezonePeriodList.new
121
+ list.add(2000, 4) { TimezonePeriod.new(DateTime.new(2000,4,1,1,0,0),DateTime.new(2000,5,1,1,0,0),-18000,3600,:'TESTD') }
122
+ list.add(2000, 10) { TimezonePeriod.new(DateTime.new(2000,10,1,1,0,0),DateTime.new(2001,3,1,1,0,0),-18000,0,:'TESTS') }
123
+
124
+ assert_raise(PeriodNotFound) {
125
+ list.period_for_utc(DateTime.new(2005,5,1,1,0,0))
126
+ }
127
+
128
+ assert_raise(PeriodNotFound) {
129
+ list.period_for_utc(DateTime.new(2005,10,1,0,59,59))
130
+ }
131
+ end
132
+
133
+ def test_period_for_utc_empty
134
+ list = TimezonePeriodList.new
135
+ assert_raise(PeriodNotFound) {
136
+ list.period_for_utc(DateTime.new(2005,1,1,0,0,0))
137
+ }
138
+ end
139
+
140
+ def test_periods_for_local
141
+ list = TimezonePeriodList.new
142
+ list.add(2000, 4) { TimezonePeriod.new(DateTime.new(2000,4,2,1,0,0),DateTime.new(2000,10,2,1,0,0),-18000,3600,:'TESTD') }
143
+ list.add(2000, 10) { TimezonePeriod.new(DateTime.new(2000,10,2,1,0,0),DateTime.new(2001,3,2,1,0,0),-18000,0,:'TESTS') }
144
+ list.add(2001, 3) { TimezonePeriod.new(DateTime.new(2001,3,2,1,0,0),DateTime.new(2001,4,2,1,0,0),-18000,3600,:'TESTD') }
145
+ list.add(2001, 4) { TimezonePeriod.new(DateTime.new(2001,4,2,1,0,0),DateTime.new(2001,10,2,1,0,0),-21600,3600,:'TESTD') }
146
+ list.add(2001, 10) { TimezonePeriod.new(DateTime.new(2001,10,2,1,0,0),DateTime.new(2002,10,2,1,0,0),-18000,0,:'TESTS') }
147
+ list.add(2002, 10) { TimezonePeriod.new(DateTime.new(2002,10,2,1,0,0),DateTime.new(2003,2,2,1,0,0),-18000,0,:'TESTS') }
148
+
149
+ # TimezonePeriodList expands out blocks and caches the results
150
+ # run twice to ensure this is being done correctly
151
+ 2.times {|i|
152
+ assert_raise(PeriodNotFound) {
153
+ list.periods_for_local(DateTime.new(1999,12,1,0,0,0))
154
+ }
155
+ assert_raise(PeriodNotFound) {
156
+ list.periods_for_local(DateTime.new(2000,4,1,20,59,59))
157
+ }
158
+
159
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2000,4,2,1,0,0),DateTime.new(2000,10,2,1,0,0),-18000,3600,:'TESTD')],
160
+ list.periods_for_local(DateTime.new(2000,4,1,21,0,0)))
161
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2000,4,2,1,0,0),DateTime.new(2000,10,2,1,0,0),-18000,3600,:'TESTD')],
162
+ list.periods_for_local(DateTime.new(2000,10,1,19,59,59)))
163
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2000,4,2,1,0,0),DateTime.new(2000,10,2,1,0,0),-18000,3600,:'TESTD'),
164
+ TimezonePeriod.new(DateTime.new(2000,10,2,1,0,0),DateTime.new(2001,3,2,1,0,0),-18000,0,:'TESTS')],
165
+ list.periods_for_local(DateTime.new(2000,10,1,20,0,0)))
166
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2000,4,2,1,0,0),DateTime.new(2000,10,2,1,0,0),-18000,3600,:'TESTD'),
167
+ TimezonePeriod.new(DateTime.new(2000,10,2,1,0,0),DateTime.new(2001,3,2,1,0,0),-18000,0,:'TESTS')],
168
+ list.periods_for_local(DateTime.new(2000,10,1,20,59,59)))
169
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2000,10,2,1,0,0),DateTime.new(2001,3,2,1,0,0),-18000,0,:'TESTS')],
170
+ list.periods_for_local(DateTime.new(2000,10,1,21,0,0)))
171
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2000,10,2,1,0,0),DateTime.new(2001,3,2,1,0,0),-18000,0,:'TESTS')],
172
+ list.periods_for_local(DateTime.new(2001,3,1,19,59,59)))
173
+
174
+ assert_raise(PeriodNotFound) {
175
+ list.periods_for_local(DateTime.new(2001,3,1,20,0,0))
176
+ }
177
+ assert_raise(PeriodNotFound) {
178
+ list.periods_for_local(DateTime.new(2001,3,1,20,59,59))
179
+ }
180
+
181
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2001,3,2,1,0,0),DateTime.new(2001,4,2,1,0,0),-18000,3600,:'TESTD')],
182
+ list.periods_for_local(DateTime.new(2001,3,1,21,0,0)))
183
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2001,3,2,1,0,0),DateTime.new(2001,4,2,1,0,0),-18000,3600,:'TESTD')],
184
+ list.periods_for_local(DateTime.new(2001,4,1,19,59,59)))
185
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2001,3,2,1,0,0),DateTime.new(2001,4,2,1,0,0),-18000,3600,:'TESTD'),
186
+ TimezonePeriod.new(DateTime.new(2001,4,2,1,0,0),DateTime.new(2001,10,2,1,0,0),-21600,3600,:'TESTD')],
187
+ list.periods_for_local(DateTime.new(2001,4,1,20,0,0)))
188
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2001,3,2,1,0,0),DateTime.new(2001,4,2,1,0,0),-18000,3600,:'TESTD'),
189
+ TimezonePeriod.new(DateTime.new(2001,4,2,1,0,0),DateTime.new(2001,10,2,1,0,0),-21600,3600,:'TESTD')],
190
+ list.periods_for_local(DateTime.new(2001,4,1,20,59,59)))
191
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2001,4,2,1,0,0),DateTime.new(2001,10,2,1,0,0),-21600,3600,:'TESTD')],
192
+ list.periods_for_local(DateTime.new(2001,4,1,21,0,0)))
193
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2001,4,2,1,0,0),DateTime.new(2001,10,2,1,0,0),-21600,3600,:'TESTD')],
194
+ list.periods_for_local(DateTime.new(2001,10,1,19,59,59)))
195
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2001,10,2,1,0,0),DateTime.new(2002,10,2,1,0,0),-18000,0,:'TESTS')],
196
+ list.periods_for_local(DateTime.new(2001,10,1,20,0,0)))
197
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2001,10,2,1,0,0),DateTime.new(2002,10,2,1,0,0),-18000,0,:'TESTS')],
198
+ list.periods_for_local(DateTime.new(2002,2,1,20,0,0)))
199
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2001,10,2,1,0,0),DateTime.new(2002,10,2,1,0,0),-18000,0,:'TESTS')],
200
+ list.periods_for_local(DateTime.new(2002,10,1,19,59,59)))
201
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2002,10,2,1,0,0),DateTime.new(2003,2,2,1,0,0),-18000,0,:'TESTS')],
202
+ list.periods_for_local(DateTime.new(2002,10,1,20,0,0)))
203
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2002,10,2,1,0,0),DateTime.new(2003,2,2,1,0,0),-18000,0,:'TESTS')],
204
+ list.periods_for_local(DateTime.new(2003,2,1,19,59,59)))
205
+
206
+ assert_raise(PeriodNotFound) {
207
+ list.periods_for_local(DateTime.new(2003,2,1,20,0,0))
208
+ }
209
+ assert_raise(PeriodNotFound) {
210
+ list.periods_for_local(DateTime.new(2004,1,1,20,0,0))
211
+ }
212
+ }
213
+ end
214
+
215
+ def test_period_for_local_unbounded
216
+ list = TimezonePeriodList.new
217
+ list.add_unbounded_start { TimezonePeriod.new(nil,DateTime.new(2000,10,2,1,0,0),-18000,3600,:'TESTD') }
218
+ list.add(2000, 10) { TimezonePeriod.new(DateTime.new(2000,10,2,1,0,0),DateTime.new(2001,3,2,1,0,0),-18000,0,:'TESTS') }
219
+ list.add(2001, 3) { TimezonePeriod.new(DateTime.new(2001,3,2,1,0,0),nil,-18000,3600,:'TESTD') }
220
+
221
+ assert_periods_equal([TimezonePeriod.new(nil,DateTime.new(2000,10,2,1,0,0),-18000,3600,:'TESTD')],
222
+ list.periods_for_local(DateTime.new(1999,12,1,1,0,0)))
223
+ assert_periods_equal([TimezonePeriod.new(nil,DateTime.new(2000,10,2,1,0,0),-18000,3600,:'TESTD')],
224
+ list.periods_for_local(DateTime.new(2000,10,1,20,59,59)))
225
+ assert_periods_equal([TimezonePeriod.new(nil,DateTime.new(2000,10,2,1,0,0),-18000,3600,:'TESTD')],
226
+ list.periods_for_local(DateTime.new(2000,10,1,19,59,59)))
227
+ assert_periods_equal([TimezonePeriod.new(nil,DateTime.new(2000,10,2,1,0,0),-18000,3600,:'TESTD'),
228
+ TimezonePeriod.new(DateTime.new(2000,10,2,1,0,0),DateTime.new(2001,3,2,1,0,0),-18000,0,:'TESTS')],
229
+ list.periods_for_local(DateTime.new(2000,10,1,20,0,0)))
230
+ assert_periods_equal([TimezonePeriod.new(nil,DateTime.new(2000,10,2,1,0,0),-18000,3600,:'TESTD'),
231
+ TimezonePeriod.new(DateTime.new(2000,10,2,1,0,0),DateTime.new(2001,3,2,1,0,0),-18000,0,:'TESTS')],
232
+ list.periods_for_local(DateTime.new(2000,10,1,20,59,59)))
233
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2000,10,2,1,0,0),DateTime.new(2001,3,2,1,0,0),-18000,0,:'TESTS')],
234
+ list.periods_for_local(DateTime.new(2000,10,1,21,0,0)))
235
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2000,10,2,1,0,0),DateTime.new(2001,3,2,1,0,0),-18000,0,:'TESTS')],
236
+ list.periods_for_local(DateTime.new(2001,3,1,19,59,59)))
237
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2000,10,2,1,0,0),DateTime.new(2001,3,2,1,0,0),-18000,0,:'TESTS')],
238
+ list.periods_for_local(DateTime.new(2001,3,1,19,59,59)))
239
+
240
+ assert_raise(PeriodNotFound) {
241
+ list.periods_for_local(DateTime.new(2001,3,1,20,0,0))
242
+ }
243
+ assert_raise(PeriodNotFound) {
244
+ list.periods_for_local(DateTime.new(2001,3,1,20,59,59))
245
+ }
246
+
247
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2001,3,2,1,0,0),nil,-18000,3600,:'TESTD')],
248
+ list.periods_for_local(DateTime.new(2001,3,1,21,0,0)))
249
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2001,3,2,1,0,0),nil,-18000,3600,:'TESTD')],
250
+ list.periods_for_local(DateTime.new(2002,1,1,21,0,0)))
251
+ end
252
+
253
+ def test_period_for_local_unbounded
254
+ list = TimezonePeriodList.new
255
+ list.add_unbounded_start { TimezonePeriod.new(nil,DateTime.new(2000,7,1,0,0,0),-3600,0,:'TESTD') }
256
+ list.add(2000, 7) { TimezonePeriod.new(DateTime.new(2000,7,1,0,0,0),nil,-3600,0,:'TESTS') }
257
+
258
+ # 2000-07-01 00:00:00 UTC is 2000-06-30 23:00:00 UTC-1
259
+ # hence to find periods for local times between 2000-06-30 23:00:00
260
+ # and 2000-07-01 00:00:00 a search has to be carried out in the next half
261
+ # year to the one containing the date we are looking for
262
+
263
+ assert_periods_equal([TimezonePeriod.new(nil,DateTime.new(2000,7,1,0,0,0),-3600,0,:'TESTD')],
264
+ list.periods_for_local(DateTime.new(2000,6,30,22,59,59)))
265
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2000,7,1,0,0,0),nil,-3600,0,:'TESTS')],
266
+ list.periods_for_local(DateTime.new(2000,6,30,23,0,0)))
267
+ assert_periods_equal([TimezonePeriod.new(DateTime.new(2000,7,1,0,0,0),nil,-3600,0,:'TESTS')],
268
+ list.periods_for_local(DateTime.new(2000,7,1,0,0,0)))
269
+ end
270
+
271
+ private
272
+ def assert_period_equal(expected, actual)
273
+ assert_equal(expected.utc_start, actual.utc_start)
274
+ assert_equal(expected.utc_end, actual.utc_end)
275
+ assert_equal(expected.utc_offset, actual.utc_offset)
276
+ assert_equal(expected.std_offset, actual.std_offset)
277
+ assert_equal(expected.zone_identifier, actual.zone_identifier)
278
+ assert_equal(expected.local_start, actual.local_start)
279
+ assert_equal(expected.local_end, actual.local_end)
280
+ end
281
+
282
+ def assert_periods_equal(expected, actual)
283
+ assert_equal(expected.length, actual.length)
284
+ (0..expected.length - 1).each {|i|
285
+ assert_period_equal(expected[i], actual[i])
286
+ }
287
+ end
288
+ end