PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/training-web/vendor/bundle/gems/tzinfo-0.3.37/test/tc_timezone_period.rb

https://bitbucket.org/ohimmelreich/asalia-training
Ruby | 509 lines | 427 code | 82 blank | 0 comment | 25 complexity | 7459b0d2c5f4f10ad28e9a3ea6d51775 MD5 | raw file
  1. $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
  2. require 'test/unit'
  3. require 'tzinfo'
  4. include TZInfo
  5. class TCTimezonePeriod < Test::Unit::TestCase
  6. def test_initialize_start_end
  7. std = TimezoneOffsetInfo.new(-7200, 0, :TEST)
  8. dst = TimezoneOffsetInfo.new(-7200, 3600, :TEST)
  9. start_t = TimezoneTransitionInfo.new(dst, std, 1136073600)
  10. end_t = TimezoneTransitionInfo.new(std, dst, 1136160000)
  11. p = TimezonePeriod.new(start_t, end_t)
  12. assert_equal(start_t, p.start_transition)
  13. assert_equal(end_t, p.end_transition)
  14. assert_equal(dst, p.offset)
  15. assert_equal(DateTime.new(2006,1,1,0,0,0), p.utc_start)
  16. assert_equal(DateTime.new(2006,1,2,0,0,0), p.utc_end)
  17. assert_equal(-7200, p.utc_offset)
  18. assert_equal(3600, p.std_offset)
  19. assert_equal(-3600, p.utc_total_offset)
  20. assert_equal(Rational(-3600, 86400), p.utc_total_offset_rational)
  21. assert_equal(:TEST, p.zone_identifier)
  22. assert_equal(:TEST, p.abbreviation)
  23. assert_equal(DateTime.new(2005,12,31,23,0,0), p.local_start)
  24. assert_equal(DateTime.new(2006,1,1,23,0,0), p.local_end)
  25. end
  26. def test_initialize_start_end_offset
  27. std = TimezoneOffsetInfo.new(-7200, 0, :TEST)
  28. dst = TimezoneOffsetInfo.new(-7200, 3600, :TEST)
  29. special = TimezoneOffsetInfo.new(0, 0, :SPECIAL)
  30. start_t = TimezoneTransitionInfo.new(dst, std, 1136073600)
  31. end_t = TimezoneTransitionInfo.new(std, dst, 1136160000)
  32. assert_raises(ArgumentError) { TimezonePeriod.new(start_t, end_t, special) }
  33. end
  34. def test_initialize_start
  35. std = TimezoneOffsetInfo.new(-7200, 0, :TEST)
  36. dst = TimezoneOffsetInfo.new(-7200, 3600, :TEST)
  37. start_t = TimezoneTransitionInfo.new(dst, std, 1136073600)
  38. p = TimezonePeriod.new(start_t, nil)
  39. assert_equal(start_t, p.start_transition)
  40. assert_nil(p.end_transition)
  41. assert_equal(dst, p.offset)
  42. assert_equal(DateTime.new(2006,1,1,0,0,0), p.utc_start)
  43. assert_nil(p.utc_end)
  44. assert_equal(-7200, p.utc_offset)
  45. assert_equal(3600, p.std_offset)
  46. assert_equal(-3600, p.utc_total_offset)
  47. assert_equal(Rational(-3600, 86400), p.utc_total_offset_rational)
  48. assert_equal(:TEST, p.zone_identifier)
  49. assert_equal(:TEST, p.abbreviation)
  50. assert_equal(DateTime.new(2005,12,31,23,0,0), p.local_start)
  51. assert_nil(p.local_end)
  52. end
  53. def test_initialize_start_offset
  54. std = TimezoneOffsetInfo.new(-7200, 0, :TEST)
  55. dst = TimezoneOffsetInfo.new(-7200, 3600, :TEST)
  56. special = TimezoneOffsetInfo.new(0, 0, :SPECIAL)
  57. start_t = TimezoneTransitionInfo.new(dst, std, 1136073600)
  58. assert_raises(ArgumentError) { TimezonePeriod.new(start_t, nil, special) }
  59. end
  60. def test_initialize_end
  61. std = TimezoneOffsetInfo.new(-7200, 0, :TEST)
  62. dst = TimezoneOffsetInfo.new(-7200, 3600, :TEST)
  63. end_t = TimezoneTransitionInfo.new(std, dst, 1136160000)
  64. p = TimezonePeriod.new(nil, end_t)
  65. assert_nil(p.start_transition)
  66. assert_equal(end_t, p.end_transition)
  67. assert_equal(dst, p.offset)
  68. assert_nil(p.utc_start)
  69. assert_equal(DateTime.new(2006,1,2,0,0,0), p.utc_end)
  70. assert_equal(-7200, p.utc_offset)
  71. assert_equal(3600, p.std_offset)
  72. assert_equal(-3600, p.utc_total_offset)
  73. assert_equal(Rational(-3600, 86400), p.utc_total_offset_rational)
  74. assert_equal(:TEST, p.zone_identifier)
  75. assert_equal(:TEST, p.abbreviation)
  76. assert_nil(p.local_start)
  77. assert_equal(DateTime.new(2006,1,1,23,0,0), p.local_end)
  78. end
  79. def test_initialize_end_offset
  80. std = TimezoneOffsetInfo.new(-7200, 0, :TEST)
  81. dst = TimezoneOffsetInfo.new(-7200, 3600, :TEST)
  82. special = TimezoneOffsetInfo.new(0, 0, :SPECIAL)
  83. end_t = TimezoneTransitionInfo.new(std, dst, 1136160000)
  84. assert_raises(ArgumentError) { TimezonePeriod.new(nil, end_t, special) }
  85. end
  86. def test_initialize
  87. assert_raises(ArgumentError) { TimezonePeriod.new(nil, nil) }
  88. end
  89. def test_initialize_offset
  90. special = TimezoneOffsetInfo.new(0, 0, :SPECIAL)
  91. p = TimezonePeriod.new(nil, nil, special)
  92. assert_nil(p.start_transition)
  93. assert_nil(p.end_transition)
  94. assert_equal(special, p.offset)
  95. assert_nil(p.utc_start)
  96. assert_nil(p.utc_end)
  97. assert_equal(0, p.utc_offset)
  98. assert_equal(0, p.std_offset)
  99. assert_equal(0, p.utc_total_offset)
  100. assert_equal(Rational(0, 86400), p.utc_total_offset_rational)
  101. assert_equal(:SPECIAL, p.zone_identifier)
  102. assert_equal(:SPECIAL, p.abbreviation)
  103. assert_nil(p.local_start)
  104. assert_nil(p.local_end)
  105. end
  106. def test_dst
  107. p1 = TimezonePeriod.new(nil, nil, TimezoneOffsetInfo.new(-14400, 3600, :TEST))
  108. p2 = TimezonePeriod.new(nil, nil, TimezoneOffsetInfo.new(-14400, 0, :TEST))
  109. p3 = TimezonePeriod.new(nil, nil, TimezoneOffsetInfo.new(-14400, -3600, :TEST))
  110. p4 = TimezonePeriod.new(nil, nil, TimezoneOffsetInfo.new(-14400, 7200, :TEST))
  111. p5 = TimezonePeriod.new(nil, nil, TimezoneOffsetInfo.new(-14400, -7200, :TEST))
  112. assert_equal(true, p1.dst?)
  113. assert_equal(false, p2.dst?)
  114. assert_equal(true, p3.dst?)
  115. assert_equal(true, p4.dst?)
  116. assert_equal(true, p5.dst?)
  117. end
  118. def test_valid_for_utc
  119. offset = TimezoneOffsetInfo.new(-7200, 3600, :TEST)
  120. t1 = TimezoneTransitionInfo.new(offset, offset, 1104541261)
  121. t2 = TimezoneTransitionInfo.new(offset, offset, 1107309722)
  122. t3 = TimezoneTransitionInfo.new(offset, offset, 210551144461, 86400)
  123. t4 = TimezoneTransitionInfo.new(offset, offset, 105276956461, 43200)
  124. p1 = TimezonePeriod.new(t1, t2)
  125. p2 = TimezonePeriod.new(nil, t2)
  126. p3 = TimezonePeriod.new(t1, nil)
  127. p4 = TimezonePeriod.new(nil, nil, offset)
  128. p5 = TimezonePeriod.new(t3, t4)
  129. assert_equal(true, p1.valid_for_utc?(DateTime.new(2005,1,1,1,1,1)))
  130. assert_equal(true, p1.valid_for_utc?(Time.utc(2005,2,2,2,2,1)))
  131. assert_equal(true, p1.valid_for_utc?(1104541262))
  132. assert_equal(true, p1.valid_for_utc?(DateTime.new(2005,2,2,2,2,0)))
  133. assert_equal(false, p1.valid_for_utc?(DateTime.new(2005,1,1,1,1,0)))
  134. assert_equal(false, p1.valid_for_utc?(DateTime.new(2005,2,2,2,2,3)))
  135. assert_equal(false, p1.valid_for_utc?(DateTime.new(1960,1,1,1,1,0)))
  136. assert_equal(false, p1.valid_for_utc?(DateTime.new(2040,1,1,1,1,0)))
  137. assert_equal(true, p2.valid_for_utc?(DateTime.new(2005,1,1,1,1,1)))
  138. assert_equal(true, p2.valid_for_utc?(Time.utc(2005,2,2,2,2,1)))
  139. assert_equal(true, p2.valid_for_utc?(1104541262))
  140. assert_equal(true, p2.valid_for_utc?(DateTime.new(2005,2,2,2,2,0)))
  141. assert_equal(true, p2.valid_for_utc?(DateTime.new(2005,1,1,1,1,0)))
  142. assert_equal(false, p2.valid_for_utc?(DateTime.new(2005,2,2,2,2,3)))
  143. assert_equal(true, p2.valid_for_utc?(DateTime.new(1960,1,1,1,1,0)))
  144. assert_equal(false, p2.valid_for_utc?(DateTime.new(2040,1,1,1,1,0)))
  145. assert_equal(true, p3.valid_for_utc?(DateTime.new(2005,1,1,1,1,1)))
  146. assert_equal(true, p3.valid_for_utc?(Time.utc(2005,2,2,2,2,1)))
  147. assert_equal(true, p3.valid_for_utc?(1104541262))
  148. assert_equal(true, p3.valid_for_utc?(DateTime.new(2005,2,2,2,2,0)))
  149. assert_equal(false, p3.valid_for_utc?(DateTime.new(2005,1,1,1,1,0)))
  150. assert_equal(true, p3.valid_for_utc?(DateTime.new(2005,2,2,2,2,3)))
  151. assert_equal(false, p3.valid_for_utc?(DateTime.new(1960,1,1,1,1,0)))
  152. assert_equal(true, p3.valid_for_utc?(DateTime.new(2040,1,1,1,1,0)))
  153. assert_equal(true, p4.valid_for_utc?(DateTime.new(2005,1,1,1,1,1)))
  154. assert_equal(true, p4.valid_for_utc?(Time.utc(2005,2,2,2,2,1)))
  155. assert_equal(true, p4.valid_for_utc?(1104541262))
  156. assert_equal(true, p4.valid_for_utc?(DateTime.new(2005,2,2,2,2,0)))
  157. assert_equal(true, p4.valid_for_utc?(DateTime.new(2005,1,1,1,1,0)))
  158. assert_equal(true, p4.valid_for_utc?(DateTime.new(2005,2,2,2,2,3)))
  159. assert_equal(true, p4.valid_for_utc?(DateTime.new(1960,1,1,1,1,0)))
  160. assert_equal(true, p4.valid_for_utc?(DateTime.new(2040,1,1,1,1,0)))
  161. assert_equal(false, p5.valid_for_utc?(Time.utc(2005,1,1,1,1,1)))
  162. assert_equal(false, p5.valid_for_utc?(1104541262))
  163. end
  164. def test_utc_after_start
  165. offset = TimezoneOffsetInfo.new(-7200, 3600, :TEST)
  166. t1 = TimezoneTransitionInfo.new(offset, offset, 1104541261)
  167. t2 = TimezoneTransitionInfo.new(offset, offset, 1107309722)
  168. t3 = TimezoneTransitionInfo.new(offset, offset, 210077845261, 86400)
  169. t4 = TimezoneTransitionInfo.new(offset, offset, 105040306861, 43200)
  170. p1 = TimezonePeriod.new(t1, t2)
  171. p2 = TimezonePeriod.new(nil, t2)
  172. p3 = TimezonePeriod.new(t3, t4)
  173. assert_equal(true, p1.utc_after_start?(DateTime.new(2005,1,1,1,1,1)))
  174. assert_equal(true, p1.utc_after_start?(Time.utc(2005,1,1,1,1,2)))
  175. assert_equal(false, p1.utc_after_start?(1104541260))
  176. assert_equal(true, p1.utc_after_start?(DateTime.new(2045,1,1,1,1,0)))
  177. assert_equal(false, p1.utc_after_start?(DateTime.new(1955,1,1,1,1,0)))
  178. assert_equal(true, p2.utc_after_start?(DateTime.new(2005,1,1,1,1,1)))
  179. assert_equal(true, p2.utc_after_start?(Time.utc(2005,1,1,1,1,2)))
  180. assert_equal(true, p2.utc_after_start?(1104541260))
  181. assert_equal(true, p3.utc_after_start?(Time.utc(2005,1,2,1,1,1)))
  182. assert_equal(true, p3.utc_after_start?(1104627661))
  183. end
  184. def test_utc_before_end
  185. offset = TimezoneOffsetInfo.new(-7200, 3600, :TEST)
  186. t1 = TimezoneTransitionInfo.new(offset, offset, 1104541261)
  187. t2 = TimezoneTransitionInfo.new(offset, offset, 1107309722)
  188. t3 = TimezoneTransitionInfo.new(offset, offset, 210077845261, 86400)
  189. t4 = TimezoneTransitionInfo.new(offset, offset, 105040306861, 43200)
  190. p1 = TimezonePeriod.new(t1, t2)
  191. p2 = TimezonePeriod.new(t1, nil)
  192. p3 = TimezonePeriod.new(t3, t4)
  193. assert_equal(true, p1.utc_before_end?(DateTime.new(2005,2,2,2,2,1)))
  194. assert_equal(true, p1.utc_before_end?(Time.utc(2005,2,2,2,2,0)))
  195. assert_equal(false, p1.utc_before_end?(1107309723))
  196. assert_equal(false, p1.utc_before_end?(DateTime.new(2045,1,1,1,1,0)))
  197. assert_equal(true, p1.utc_before_end?(DateTime.new(1955,1,1,1,1,0)))
  198. assert_equal(true, p2.utc_before_end?(DateTime.new(2005,2,2,2,2,1)))
  199. assert_equal(true, p2.utc_before_end?(Time.utc(2005,2,2,2,2,0)))
  200. assert_equal(true, p2.utc_before_end?(1107309723))
  201. assert_equal(false, p3.utc_before_end?(Time.utc(2005,1,2,1,1,1)))
  202. assert_equal(false, p3.utc_before_end?(1104627661))
  203. end
  204. def test_valid_for_local
  205. offset = TimezoneOffsetInfo.new(-7200, 3600, :TEST)
  206. t1 = TimezoneTransitionInfo.new(offset, offset, 1104544861)
  207. t2 = TimezoneTransitionInfo.new(offset, offset, 1107313322)
  208. t3 = TimezoneTransitionInfo.new(offset, offset, 1104544861)
  209. t4 = TimezoneTransitionInfo.new(offset, offset, 210551144461, 86400)
  210. t5 = TimezoneTransitionInfo.new(offset, offset, 105276956461, 43200)
  211. p1 = TimezonePeriod.new(t1, t2)
  212. p2 = TimezonePeriod.new(nil, t2)
  213. p3 = TimezonePeriod.new(t3, nil)
  214. p4 = TimezonePeriod.new(nil, nil, offset)
  215. p5 = TimezonePeriod.new(t4, t5)
  216. assert_equal(true, p1.valid_for_local?(DateTime.new(2005,1,1,1,1,1)))
  217. assert_equal(true, p1.valid_for_local?(Time.utc(2005,2,2,2,2,1)))
  218. assert_equal(true, p1.valid_for_local?(1104541262))
  219. assert_equal(true, p1.valid_for_local?(DateTime.new(2005,2,2,2,2,0)))
  220. assert_equal(false, p1.valid_for_local?(DateTime.new(2005,1,1,1,1,0)))
  221. assert_equal(false, p1.valid_for_local?(DateTime.new(2005,2,2,2,2,3)))
  222. assert_equal(false, p1.valid_for_local?(DateTime.new(1960,1,1,1,1,0)))
  223. assert_equal(false, p1.valid_for_local?(DateTime.new(2040,1,1,1,1,0)))
  224. assert_equal(true, p2.valid_for_local?(DateTime.new(2005,1,1,1,1,1)))
  225. assert_equal(true, p2.valid_for_local?(DateTime.new(2005,2,2,2,2,1)))
  226. assert_equal(true, p2.valid_for_local?(1104541262))
  227. assert_equal(true, p2.valid_for_local?(DateTime.new(2005,2,2,2,2,0)))
  228. assert_equal(true, p2.valid_for_local?(DateTime.new(2005,1,1,1,1,0)))
  229. assert_equal(false, p2.valid_for_local?(DateTime.new(2005,2,2,2,2,3)))
  230. assert_equal(true, p2.valid_for_local?(DateTime.new(1960,1,1,1,1,0)))
  231. assert_equal(false, p2.valid_for_local?(DateTime.new(2040,1,1,1,1,0)))
  232. assert_equal(true, p3.valid_for_local?(DateTime.new(2005,1,1,1,1,1)))
  233. assert_equal(true, p3.valid_for_local?(DateTime.new(2005,2,2,2,2,1)))
  234. assert_equal(true, p3.valid_for_local?(1104541262))
  235. assert_equal(true, p3.valid_for_local?(DateTime.new(2005,2,2,2,2,0)))
  236. assert_equal(false, p3.valid_for_local?(DateTime.new(2005,1,1,1,1,0)))
  237. assert_equal(true, p3.valid_for_local?(DateTime.new(2005,2,2,2,2,3)))
  238. assert_equal(false, p3.valid_for_local?(DateTime.new(1960,1,1,1,1,0)))
  239. assert_equal(true, p3.valid_for_local?(DateTime.new(2040,1,1,1,1,0)))
  240. assert_equal(true, p4.valid_for_local?(DateTime.new(2005,1,1,1,1,1)))
  241. assert_equal(true, p4.valid_for_local?(DateTime.new(2005,2,2,2,2,1)))
  242. assert_equal(true, p4.valid_for_local?(1104541262))
  243. assert_equal(true, p4.valid_for_local?(DateTime.new(2005,2,2,2,2,0)))
  244. assert_equal(true, p4.valid_for_local?(DateTime.new(2005,1,1,1,1,0)))
  245. assert_equal(true, p4.valid_for_local?(DateTime.new(2005,2,2,2,2,3)))
  246. assert_equal(true, p4.valid_for_local?(DateTime.new(1960,1,1,1,1,0)))
  247. assert_equal(true, p4.valid_for_local?(DateTime.new(2040,1,1,1,1,0)))
  248. assert_equal(false, p5.valid_for_utc?(Time.utc(2005,1,1,1,1,1)))
  249. assert_equal(false, p5.valid_for_utc?(1104541262))
  250. end
  251. def test_local_after_start
  252. offset = TimezoneOffsetInfo.new(-7200, 3600, :TEST)
  253. t1 = TimezoneTransitionInfo.new(offset, offset, 1104544861)
  254. t2 = TimezoneTransitionInfo.new(offset, offset, 1107313322)
  255. t3 = TimezoneTransitionInfo.new(offset, offset, 210077845261, 86400)
  256. t4 = TimezoneTransitionInfo.new(offset, offset, 105040306861, 43200)
  257. p1 = TimezonePeriod.new(t1, t2)
  258. p2 = TimezonePeriod.new(nil, t2)
  259. p3 = TimezonePeriod.new(t3, t4)
  260. assert_equal(true, p1.local_after_start?(DateTime.new(2005,1,1,1,1,1)))
  261. assert_equal(true, p1.local_after_start?(Time.utc(2005,1,1,1,1,2)))
  262. assert_equal(false, p1.local_after_start?(1104541260))
  263. assert_equal(true, p1.local_after_start?(DateTime.new(2045,1,1,1,1,0)))
  264. assert_equal(false, p1.local_after_start?(DateTime.new(1955,1,1,1,1,0)))
  265. assert_equal(true, p2.local_after_start?(DateTime.new(2005,1,1,1,1,1)))
  266. assert_equal(true, p2.local_after_start?(Time.utc(2005,1,1,1,1,2)))
  267. assert_equal(true, p2.local_after_start?(1104541260))
  268. assert_equal(true, p3.local_after_start?(Time.utc(2005,1,2,1,1,1)))
  269. assert_equal(true, p3.local_after_start?(1104627661))
  270. end
  271. def test_local_before_end
  272. offset = TimezoneOffsetInfo.new(-7200, 3600, :TEST)
  273. t1 = TimezoneTransitionInfo.new(offset, offset, 1104544861)
  274. t2 = TimezoneTransitionInfo.new(offset, offset, 1107313322)
  275. t3 = TimezoneTransitionInfo.new(offset, offset, 210077845261, 86400)
  276. t4 = TimezoneTransitionInfo.new(offset, offset, 105040306861, 43200)
  277. p1 = TimezonePeriod.new(t1, t2)
  278. p2 = TimezonePeriod.new(t1, nil)
  279. p3 = TimezonePeriod.new(t3, t4)
  280. assert_equal(true, p1.local_before_end?(DateTime.new(2005,2,2,2,2,1)))
  281. assert_equal(true, p1.local_before_end?(Time.utc(2005,2,2,2,2,0)))
  282. assert_equal(false, p1.local_before_end?(1107309723))
  283. assert_equal(false, p1.local_before_end?(DateTime.new(2045,1,1,1,1,0)))
  284. assert_equal(true, p1.local_before_end?(DateTime.new(1955,1,1,1,1,0)))
  285. assert_equal(true, p2.local_before_end?(DateTime.new(2005,2,2,2,2,1)))
  286. assert_equal(true, p2.local_before_end?(Time.utc(2005,2,2,2,2,0)))
  287. assert_equal(true, p2.local_before_end?(1107309723))
  288. assert_equal(false, p3.local_before_end?(Time.utc(2005,1,2,1,1,1)))
  289. assert_equal(false, p3.local_before_end?(1104627661))
  290. end
  291. def test_to_local
  292. p1 = TimezonePeriod.new(nil, nil, TimezoneOffsetInfo.new(-14400, 3600, :TEST))
  293. p2 = TimezonePeriod.new(nil, nil, TimezoneOffsetInfo.new(-14400, 0, :TEST))
  294. p3 = TimezonePeriod.new(nil, nil, TimezoneOffsetInfo.new(7200, 3600, :TEST))
  295. assert_equal(DateTime.new(2005,1,19,22,0,0), p1.to_local(DateTime.new(2005,1,20,1,0,0)))
  296. assert_equal(Time.utc(2005,1,19,21,0,0), p2.to_local(Time.utc(2005,1,20,1,0,0)))
  297. assert_equal(1106193600, p3.to_local(1106182800))
  298. end
  299. def test_to_utc
  300. p1 = TimezonePeriod.new(nil, nil, TimezoneOffsetInfo.new(-14400, 3600, :TEST))
  301. p2 = TimezonePeriod.new(nil, nil, TimezoneOffsetInfo.new(-14400, 0, :TEST))
  302. p3 = TimezonePeriod.new(nil, nil, TimezoneOffsetInfo.new(7200, 3600, :TEST))
  303. assert_equal(DateTime.new(2005,1,20,4,0,0), p1.to_utc(DateTime.new(2005,1,20,1,0,0)))
  304. assert_equal(Time.utc(2005,1,20,5,0,0), p2.to_utc(Time.utc(2005,1,20,1,0,0)))
  305. assert_equal(1106172000, p3.to_utc(1106182800))
  306. end
  307. def test_time_boundary_start
  308. o1 = TimezoneOffsetInfo.new(-3600, 0, :TEST)
  309. o2 = TimezoneOffsetInfo.new(-3600, 3600, :TEST)
  310. t1 = TimezoneTransitionInfo.new(o1, o2, 0)
  311. p1 = TimezonePeriod.new(t1, nil)
  312. assert_equal(DateTime.new(1969,12,31,23,0,0), p1.local_start)
  313. end
  314. def test_time_boundary_end
  315. o1 = TimezoneOffsetInfo.new(0, 3600, :TEST)
  316. o2 = TimezoneOffsetInfo.new(0, 0, :TEST)
  317. t1 = TimezoneTransitionInfo.new(o2, o1, 2147482800)
  318. p1 = TimezonePeriod.new(nil, t1)
  319. assert_equal(DateTime.new(2038,1,19,4,0,0), p1.local_end)
  320. end
  321. def test_equality
  322. o1 = TimezoneOffsetInfo.new(0, 3600, :TEST)
  323. o2 = TimezoneOffsetInfo.new(0, 0, :TEST)
  324. t1 = TimezoneTransitionInfo.new(o1, o2, 1149368400)
  325. t2 = TimezoneTransitionInfo.new(o1, o2, 19631123, 8)
  326. t3 = TimezoneTransitionInfo.new(o1, o2, 1149454800)
  327. t4 = TimezoneTransitionInfo.new(o1, o2, 1149541200)
  328. p1 = TimezonePeriod.new(t1, t3)
  329. p2 = TimezonePeriod.new(t1, t3)
  330. p3 = TimezonePeriod.new(t2, t3)
  331. p4 = TimezonePeriod.new(t3, nil)
  332. p5 = TimezonePeriod.new(t3, nil)
  333. p6 = TimezonePeriod.new(t4, nil)
  334. p7 = TimezonePeriod.new(nil, t3)
  335. p8 = TimezonePeriod.new(nil, t3)
  336. p9 = TimezonePeriod.new(nil, t4)
  337. p10 = TimezonePeriod.new(nil, nil, o1)
  338. p11 = TimezonePeriod.new(nil, nil, o1)
  339. p12 = TimezonePeriod.new(nil, nil, o2)
  340. assert_equal(true, p1 == p1)
  341. assert_equal(true, p1 == p2)
  342. assert_equal(true, p1 == p3)
  343. assert_equal(false, p1 == p4)
  344. assert_equal(false, p1 == p5)
  345. assert_equal(false, p1 == p6)
  346. assert_equal(false, p1 == p7)
  347. assert_equal(false, p1 == p8)
  348. assert_equal(false, p1 == p9)
  349. assert_equal(false, p1 == p10)
  350. assert_equal(false, p1 == p11)
  351. assert_equal(false, p1 == p12)
  352. assert_equal(false, p1 == Object.new)
  353. assert_equal(true, p4 == p4)
  354. assert_equal(true, p4 == p5)
  355. assert_equal(false, p4 == p6)
  356. assert_equal(false, p4 == Object.new)
  357. assert_equal(true, p7 == p7)
  358. assert_equal(true, p7 == p8)
  359. assert_equal(false, p7 == p9)
  360. assert_equal(false, p7 == Object.new)
  361. assert_equal(true, p10 == p10)
  362. assert_equal(true, p10 == p11)
  363. assert_equal(false, p10 == p12)
  364. assert_equal(false, p10 == Object.new)
  365. end
  366. def test_eql
  367. o1 = TimezoneOffsetInfo.new(0, 3600, :TEST)
  368. o2 = TimezoneOffsetInfo.new(0, 0, :TEST)
  369. t1 = TimezoneTransitionInfo.new(o1, o2, 1149368400)
  370. t2 = TimezoneTransitionInfo.new(o1, o2, 19631123, 8)
  371. t3 = TimezoneTransitionInfo.new(o1, o2, 1149454800)
  372. t4 = TimezoneTransitionInfo.new(o1, o2, 1149541200)
  373. p1 = TimezonePeriod.new(t1, t3)
  374. p2 = TimezonePeriod.new(t1, t3)
  375. p3 = TimezonePeriod.new(t2, t3)
  376. p4 = TimezonePeriod.new(t3, nil)
  377. p5 = TimezonePeriod.new(t3, nil)
  378. p6 = TimezonePeriod.new(t4, nil)
  379. p7 = TimezonePeriod.new(nil, t3)
  380. p8 = TimezonePeriod.new(nil, t3)
  381. p9 = TimezonePeriod.new(nil, t4)
  382. p10 = TimezonePeriod.new(nil, nil, o1)
  383. p11 = TimezonePeriod.new(nil, nil, o1)
  384. p12 = TimezonePeriod.new(nil, nil, o2)
  385. assert_equal(true, p1.eql?(p1))
  386. assert_equal(true, p1.eql?(p2))
  387. assert_equal(false, p1.eql?(p3))
  388. assert_equal(false, p1.eql?(p4))
  389. assert_equal(false, p1.eql?(p5))
  390. assert_equal(false, p1.eql?(p6))
  391. assert_equal(false, p1.eql?(p7))
  392. assert_equal(false, p1.eql?(p8))
  393. assert_equal(false, p1.eql?(p9))
  394. assert_equal(false, p1.eql?(p10))
  395. assert_equal(false, p1.eql?(p11))
  396. assert_equal(false, p1.eql?(p12))
  397. assert_equal(false, p1.eql?(Object.new))
  398. assert_equal(true, p4.eql?(p4))
  399. assert_equal(true, p4.eql?(p5))
  400. assert_equal(false, p4.eql?(p6))
  401. assert_equal(false, p4.eql?(Object.new))
  402. assert_equal(true, p7.eql?(p7))
  403. assert_equal(true, p7.eql?(p8))
  404. assert_equal(false, p7.eql?(p9))
  405. assert_equal(false, p7.eql?(Object.new))
  406. assert_equal(true, p10.eql?(p10))
  407. assert_equal(true, p10.eql?(p11))
  408. assert_equal(false, p10.eql?(p12))
  409. assert_equal(false, p10.eql?(Object.new))
  410. end
  411. def test_hash
  412. o1 = TimezoneOffsetInfo.new(0, 3600, :TEST)
  413. o2 = TimezoneOffsetInfo.new(0, 0, :TEST)
  414. t1 = TimezoneTransitionInfo.new(o1, o2, 1149368400)
  415. t2 = TimezoneTransitionInfo.new(o1, o2, 19631123, 8)
  416. t3 = TimezoneTransitionInfo.new(o1, o2, 1149454800)
  417. t4 = TimezoneTransitionInfo.new(o1, o2, 1149541200)
  418. p1 = TimezonePeriod.new(t1, t3)
  419. p2 = TimezonePeriod.new(t3, nil)
  420. p3 = TimezonePeriod.new(nil, t3)
  421. p4 = TimezonePeriod.new(nil, nil, o1)
  422. assert_equal(t1.hash ^ t3.hash, p1.hash)
  423. assert_equal(t3.hash ^ nil.hash, p2.hash)
  424. assert_equal(nil.hash ^ t3.hash, p3.hash)
  425. assert_equal(nil.hash ^ nil.hash ^ o1.hash, p4.hash)
  426. end
  427. end