PageRenderTime 54ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/ohimmelreich/asalia-training
Ruby | 282 lines | 221 code | 54 blank | 7 comment | 0 complexity | 1e21c87345ac05f291c8d4ea5fba0f56 MD5 | raw file
  1. $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
  2. require 'test/unit'
  3. require 'tzinfo'
  4. include TZInfo
  5. class TCDataTimezoneInfo < Test::Unit::TestCase
  6. def test_identifier
  7. dti = DataTimezoneInfo.new('Test/Zone')
  8. assert_equal('Test/Zone', dti.identifier)
  9. end
  10. def test_offset
  11. dti = DataTimezoneInfo.new('Test/Zone')
  12. # Test nothing raised
  13. dti.offset :o1, -18000, 3600, :TEST
  14. end
  15. def test_offset_already_defined
  16. dti = DataTimezoneInfo.new('Test/Zone')
  17. dti.offset :o1, 3600, 0, :TEST
  18. dti.offset :o2, 1800, 0, :TEST2
  19. assert_raises(ArgumentError) { dti.offset :o1, 3600, 3600, :TESTD }
  20. end
  21. def test_transition_time
  22. dti = DataTimezoneInfo.new('Test/Zone')
  23. dti.offset :o1, -18000, 3600, :TEST
  24. # Test nothing raised
  25. dti.transition 2006, 6, :o1, 1149368400
  26. end
  27. def test_transition_datetime
  28. dti = DataTimezoneInfo.new('Test/Zone')
  29. dti.offset :o1, -18000, 3600, :TEST
  30. # Test nothing raised
  31. dti.transition 2006, 6, :o1, 19631123, 8
  32. end
  33. def test_transition_invalid_offset
  34. dti = DataTimezoneInfo.new('Test/Zone')
  35. dti.offset :o1, -18000, 3600, :TEST
  36. dti.transition 2006, 6, :o1, 1149368400
  37. assert_raises(ArgumentError) { dti.transition 2006, 6, :o2, 1149454800 }
  38. end
  39. def test_transition_no_offsets
  40. dti = DataTimezoneInfo.new('Test/Zone')
  41. assert_raises(ArgumentError) { dti.transition 2006, 6, :o1, 1149368400 }
  42. end
  43. def test_transition_invalid_order_month
  44. dti = DataTimezoneInfo.new('Test/Zone')
  45. dti.offset :o1, -18000, 3600, :TEST
  46. dti.transition 2006, 6, :o1, 1149368400
  47. assert_raises(ArgumentError) { dti.transition 2006, 5, :o2, 1146690000 }
  48. end
  49. def test_transition_invalid_order_year
  50. dti = DataTimezoneInfo.new('Test/Zone')
  51. dti.offset :o1, -18000, 3600, :TEST
  52. dti.transition 2006, 6, :o1, 1149368400
  53. assert_raises(ArgumentError) { dti.transition 2005, 7, :o2, 1120424400 }
  54. end
  55. def test_period_for_utc
  56. dti = DataTimezoneInfo.new('Test/Zone')
  57. dti.offset :o1, -17900, 0, :TESTLMT
  58. dti.offset :o2, -18000, 3600, :TESTD
  59. dti.offset :o3, -18000, 0, :TESTS
  60. dti.offset :o4, -21600, 3600, :TESTD
  61. dti.transition 2000, 4, :o2, Time.utc(2000, 4,1,1,0,0).to_i
  62. dti.transition 2000, 10, :o3, Time.utc(2000,10,1,1,0,0).to_i
  63. dti.transition 2001, 3, :o2, 58847269, 24 # (2001, 3,1,1,0,0)
  64. dti.transition 2001, 4, :o4, Time.utc(2001, 4,1,1,0,0).to_i
  65. dti.transition 2001, 10, :o3, Time.utc(2001,10,1,1,0,0).to_i
  66. dti.transition 2002, 10, :o3, Time.utc(2002,10,1,1,0,0).to_i
  67. dti.transition 2003, 2, :o2, Time.utc(2003, 2,1,1,0,0).to_i
  68. dti.transition 2003, 3, :o3, Time.utc(2003, 3,1,1,0,0).to_i
  69. o1 = TimezoneOffsetInfo.new(-17900, 0, :TESTLMT)
  70. o2 = TimezoneOffsetInfo.new(-18000, 3600, :TESTD)
  71. o3 = TimezoneOffsetInfo.new(-18000, 0, :TESTS)
  72. o4 = TimezoneOffsetInfo.new(-21600, 3600, :TESTD)
  73. t1 = TimezoneTransitionInfo.new(o2, o1, Time.utc(2000, 4,1,1,0,0).to_i)
  74. t2 = TimezoneTransitionInfo.new(o3, o2, Time.utc(2000,10,1,1,0,0).to_i)
  75. t3 = TimezoneTransitionInfo.new(o2, o3, Time.utc(2001, 3,1,1,0,0).to_i)
  76. t4 = TimezoneTransitionInfo.new(o4, o2, Time.utc(2001, 4,1,1,0,0).to_i)
  77. t5 = TimezoneTransitionInfo.new(o3, o4, Time.utc(2001,10,1,1,0,0).to_i)
  78. t6 = TimezoneTransitionInfo.new(o3, o3, Time.utc(2002,10,1,1,0,0).to_i)
  79. t7 = TimezoneTransitionInfo.new(o2, o3, Time.utc(2003, 2,1,1,0,0).to_i)
  80. t8 = TimezoneTransitionInfo.new(o3, o2, Time.utc(2003, 3,1,1,0,0).to_i)
  81. assert_equal(TimezonePeriod.new(nil, t1), dti.period_for_utc(DateTime.new(1960, 1,1,1, 0, 0)))
  82. assert_equal(TimezonePeriod.new(nil, t1), dti.period_for_utc(DateTime.new(1999,12,1,0, 0, 0)))
  83. assert_equal(TimezonePeriod.new(nil, t1), dti.period_for_utc(Time.utc( 2000, 4,1,0,59,59)))
  84. assert_equal(TimezonePeriod.new(t1, t2), dti.period_for_utc(DateTime.new(2000, 4,1,1, 0, 0)))
  85. assert_equal(TimezonePeriod.new(t1, t2), dti.period_for_utc(Time.utc( 2000,10,1,0,59,59).to_i))
  86. assert_equal(TimezonePeriod.new(t2, t3), dti.period_for_utc(Time.utc( 2000,10,1,1, 0, 0)))
  87. assert_equal(TimezonePeriod.new(t2, t3), dti.period_for_utc(Time.utc( 2001, 3,1,0,59,59)))
  88. assert_equal(TimezonePeriod.new(t3, t4), dti.period_for_utc(Time.utc( 2001, 3,1,1, 0, 0)))
  89. assert_equal(TimezonePeriod.new(t3, t4), dti.period_for_utc(Time.utc( 2001, 4,1,0,59,59)))
  90. assert_equal(TimezonePeriod.new(t4, t5), dti.period_for_utc(Time.utc( 2001, 4,1,1, 0, 0)))
  91. assert_equal(TimezonePeriod.new(t4, t5), dti.period_for_utc(Time.utc( 2001,10,1,0,59,59)))
  92. assert_equal(TimezonePeriod.new(t5, t6), dti.period_for_utc(Time.utc( 2001,10,1,1, 0, 0)))
  93. assert_equal(TimezonePeriod.new(t5, t6), dti.period_for_utc(Time.utc( 2002, 2,1,1, 0, 0)))
  94. assert_equal(TimezonePeriod.new(t5, t6), dti.period_for_utc(Time.utc( 2002,10,1,0,59,59)))
  95. assert_equal(TimezonePeriod.new(t6, t7), dti.period_for_utc(Time.utc( 2002,10,1,1, 0, 0)))
  96. assert_equal(TimezonePeriod.new(t6, t7), dti.period_for_utc(Time.utc( 2003, 2,1,0,59,59)))
  97. assert_equal(TimezonePeriod.new(t7, t8), dti.period_for_utc(Time.utc( 2003, 2,1,1, 0, 0)))
  98. assert_equal(TimezonePeriod.new(t7, t8), dti.period_for_utc(Time.utc( 2003, 3,1,0,59,59)))
  99. assert_equal(TimezonePeriod.new(t8, nil), dti.period_for_utc(Time.utc( 2003, 3,1,1, 0, 0)))
  100. assert_equal(TimezonePeriod.new(t8, nil), dti.period_for_utc(Time.utc( 2004, 1,1,1, 0, 0)))
  101. assert_equal(TimezonePeriod.new(t8, nil), dti.period_for_utc(DateTime.new(2050, 1,1,1, 0, 0)))
  102. end
  103. def test_period_for_utc_no_transitions
  104. dti = DataTimezoneInfo.new('Test/Zone')
  105. dti.offset :o1, -17900, 0, :TESTLMT
  106. dti.offset :o2, -18000, 0, :TEST
  107. o1 = TimezoneOffsetInfo.new(-17900, 0, :TESTLMT)
  108. assert_equal(TimezonePeriod.new(nil, nil, o1), dti.period_for_utc(DateTime.new(2005,1,1,0,0,0)))
  109. assert_equal(TimezonePeriod.new(nil, nil, o1), dti.period_for_utc(Time.utc(2005,1,1,0,0,0)))
  110. assert_equal(TimezonePeriod.new(nil, nil, o1), dti.period_for_utc(Time.utc(2005,1,1,0,0,0).to_i))
  111. end
  112. def test_period_for_utc_no_offsets
  113. dti = DataTimezoneInfo.new('Test/Zone')
  114. assert_raises(NoOffsetsDefined) { dti.period_for_utc(DateTime.new(2005,1,1,0,0,0)) }
  115. assert_raises(NoOffsetsDefined) { dti.period_for_utc(Time.utc(2005,1,1,0,0,0)) }
  116. assert_raises(NoOffsetsDefined) { dti.period_for_utc(Time.utc(2005,1,1,0,0,0).to_i) }
  117. end
  118. def test_periods_for_local
  119. dti = DataTimezoneInfo.new('Test/Zone')
  120. dti.offset :o1, -17900, 0, :TESTLMT
  121. dti.offset :o2, -18000, 3600, :TESTD
  122. dti.offset :o3, -18000, 0, :TESTS
  123. dti.offset :o4, -21600, 3600, :TESTD
  124. dti.transition 2000, 4, :o2, 58839277, 24 # 2000,4,2,1,0,0
  125. dti.transition 2000, 10, :o3, Time.utc(2000,10,2,1,0,0).to_i
  126. dti.transition 2001, 3, :o2, Time.utc(2001, 3,2,1,0,0).to_i
  127. dti.transition 2001, 4, :o4, Time.utc(2001, 4,2,1,0,0).to_i
  128. dti.transition 2001, 10, :o3, Time.utc(2001,10,2,1,0,0).to_i
  129. dti.transition 2002, 10, :o3, 58861189, 24 # 2002,10,2,1,0,0
  130. dti.transition 2003, 2, :o2, Time.utc(2003, 2,2,1,0,0).to_i
  131. o1 = TimezoneOffsetInfo.new(-17900, 0, :TESTLMT)
  132. o2 = TimezoneOffsetInfo.new(-18000, 3600, :TESTD)
  133. o3 = TimezoneOffsetInfo.new(-18000, 0, :TESTS)
  134. o4 = TimezoneOffsetInfo.new(-21600, 3600, :TESTD)
  135. t1 = TimezoneTransitionInfo.new(o2, o1, Time.utc(2000, 4,2,1,0,0).to_i)
  136. t2 = TimezoneTransitionInfo.new(o3, o2, Time.utc(2000,10,2,1,0,0).to_i)
  137. t3 = TimezoneTransitionInfo.new(o2, o3, Time.utc(2001, 3,2,1,0,0).to_i)
  138. t4 = TimezoneTransitionInfo.new(o4, o2, Time.utc(2001, 4,2,1,0,0).to_i)
  139. t5 = TimezoneTransitionInfo.new(o3, o4, Time.utc(2001,10,2,1,0,0).to_i)
  140. t6 = TimezoneTransitionInfo.new(o3, o3, Time.utc(2002,10,2,1,0,0).to_i)
  141. t7 = TimezoneTransitionInfo.new(o2, o3, Time.utc(2003, 2,2,1,0,0).to_i)
  142. assert_equal([TimezonePeriod.new(nil, t1)], dti.periods_for_local(DateTime.new(1960, 1, 1, 1, 0, 0)))
  143. assert_equal([TimezonePeriod.new(nil, t1)], dti.periods_for_local(DateTime.new(1999,12, 1, 0, 0, 0)))
  144. assert_equal([TimezonePeriod.new(nil, t1)], dti.periods_for_local(Time.utc( 2000, 1, 1,10, 0, 0)))
  145. assert_equal([TimezonePeriod.new(nil, t1)], dti.periods_for_local(Time.utc( 2000, 4, 1,20, 1,39)))
  146. assert_equal([], dti.periods_for_local(Time.utc( 2000, 4, 1,20, 1,40)))
  147. assert_equal([], dti.periods_for_local(Time.utc( 2000, 4, 1,20,59,59)))
  148. assert_equal([TimezonePeriod.new(t1, t2)], dti.periods_for_local(Time.utc( 2000, 4, 1,21, 0, 0)))
  149. assert_equal([TimezonePeriod.new(t1, t2)], dti.periods_for_local(DateTime.new(2000,10, 1,19,59,59)))
  150. assert_equal([TimezonePeriod.new(t1, t2),
  151. TimezonePeriod.new(t2, t3)], dti.periods_for_local(Time.utc( 2000,10, 1,20, 0, 0).to_i))
  152. assert_equal([TimezonePeriod.new(t1, t2),
  153. TimezonePeriod.new(t2, t3)], dti.periods_for_local(DateTime.new(2000,10, 1,20,59,59)))
  154. assert_equal([TimezonePeriod.new(t2, t3)], dti.periods_for_local(Time.utc( 2000,10, 1,21, 0, 0)))
  155. assert_equal([TimezonePeriod.new(t2, t3)], dti.periods_for_local(Time.utc( 2001, 3, 1,19,59,59)))
  156. assert_equal([], dti.periods_for_local(Time.utc( 2001, 3, 1,20, 0, 0)))
  157. assert_equal([], dti.periods_for_local(DateTime.new(2001, 3, 1,20, 30, 0)))
  158. assert_equal([], dti.periods_for_local(Time.utc( 2001, 3, 1,20,59,59).to_i))
  159. assert_equal([TimezonePeriod.new(t3, t4)], dti.periods_for_local(Time.utc( 2001, 3, 1,21, 0, 0)))
  160. assert_equal([TimezonePeriod.new(t3, t4)], dti.periods_for_local(Time.utc( 2001, 4, 1,19,59,59)))
  161. assert_equal([TimezonePeriod.new(t3, t4),
  162. TimezonePeriod.new(t4, t5)], dti.periods_for_local(DateTime.new(2001, 4, 1,20, 0, 0)))
  163. assert_equal([TimezonePeriod.new(t3, t4),
  164. TimezonePeriod.new(t4, t5)], dti.periods_for_local(Time.utc( 2001, 4, 1,20,59,59)))
  165. assert_equal([TimezonePeriod.new(t4, t5)], dti.periods_for_local(Time.utc( 2001, 4, 1,21, 0, 0)))
  166. assert_equal([TimezonePeriod.new(t4, t5)], dti.periods_for_local(Time.utc( 2001,10, 1,19,59,59)))
  167. assert_equal([TimezonePeriod.new(t5, t6)], dti.periods_for_local(Time.utc( 2001,10, 1,20, 0, 0)))
  168. assert_equal([TimezonePeriod.new(t5, t6)], dti.periods_for_local(Time.utc( 2002, 2, 1,20, 0, 0)))
  169. assert_equal([TimezonePeriod.new(t5, t6)], dti.periods_for_local(Time.utc( 2002,10, 1,19,59,59)))
  170. assert_equal([TimezonePeriod.new(t6, t7)], dti.periods_for_local(Time.utc( 2002,10, 1,20, 0, 0)))
  171. assert_equal([TimezonePeriod.new(t6, t7)], dti.periods_for_local(Time.utc( 2003, 2, 1,19,59,59)))
  172. assert_equal([], dti.periods_for_local(Time.utc( 2003, 2, 1,20, 0, 0)))
  173. assert_equal([], dti.periods_for_local(Time.utc( 2003, 2, 1,20,59,59)))
  174. assert_equal([TimezonePeriod.new(t7, nil)], dti.periods_for_local(Time.utc( 2003, 2, 1,21, 0, 0)))
  175. assert_equal([TimezonePeriod.new(t7, nil)], dti.periods_for_local(Time.utc( 2004, 2, 1,20, 0, 0)))
  176. assert_equal([TimezonePeriod.new(t7, nil)], dti.periods_for_local(DateTime.new(2040, 2, 1,20, 0, 0)))
  177. end
  178. def test_periods_for_local_warsaw
  179. dti = DataTimezoneInfo.new('Test/Europe/Warsaw')
  180. dti.offset :o1, 5040, 0, :LMT
  181. dti.offset :o2, 5040, 0, :WMT
  182. dti.offset :o3, 3600, 0, :CET
  183. dti.offset :o4, 3600, 3600, :CEST
  184. dti.transition 1879, 12, :o2, 288925853, 120 # 1879,12,31,22,36,0
  185. dti.transition 1915, 8, :o3, 290485733, 120 # 1915, 8, 4,22,36,0
  186. dti.transition 1916, 4, :o4, 29051813, 12 # 1916, 4,30,22, 0,0
  187. o1 = TimezoneOffsetInfo.new(5040, 0, :LMT)
  188. o2 = TimezoneOffsetInfo.new(5040, 0, :WMT)
  189. o3 = TimezoneOffsetInfo.new(3600, 0, :CET)
  190. o4 = TimezoneOffsetInfo.new(3600, 3600, :CEST)
  191. t1 = TimezoneTransitionInfo.new(o2, o1, 288925853, 120)
  192. t2 = TimezoneTransitionInfo.new(o3, o2, 290485733, 120)
  193. t3 = TimezoneTransitionInfo.new(o4, o3, 29051813, 12)
  194. assert_equal([TimezonePeriod.new(t1, t2),
  195. TimezonePeriod.new(t2, t3)], dti.periods_for_local(DateTime.new(1915,8,4,23,40,0)))
  196. end
  197. def test_periods_for_local_boundary
  198. dti = DataTimezoneInfo.new('Test/Zone')
  199. dti.offset :o1, -3600, 0, :TESTD
  200. dti.offset :o2, -3600, 0, :TESTS
  201. dti.transition 2000, 7, :o2, Time.utc(2000,7,1,0,0,0).to_i
  202. o1 = TimezoneOffsetInfo.new(-3600, 0, :TESTD)
  203. o2 = TimezoneOffsetInfo.new(-3600, 0, :TESTS)
  204. t1 = TimezoneTransitionInfo.new(o2, o1, Time.utc(2000,7,1,0,0,0).to_i)
  205. # 2000-07-01 00:00:00 UTC is 2000-06-30 23:00:00 UTC-1
  206. # hence to find periods for local times between 2000-06-30 23:00:00
  207. # and 2000-07-01 00:00:00 a search has to be carried out in the next half
  208. # year to the one containing the date we are looking for
  209. assert_equal([TimezonePeriod.new(nil, t1)], dti.periods_for_local(Time.utc(2000,6,30,22,59,59)))
  210. assert_equal([TimezonePeriod.new(t1, nil)], dti.periods_for_local(Time.utc(2000,6,30,23, 0, 0)))
  211. assert_equal([TimezonePeriod.new(t1, nil)], dti.periods_for_local(Time.utc(2000,7, 1, 0, 0, 0)))
  212. end
  213. def test_periods_for_local_no_transitions
  214. dti = DataTimezoneInfo.new('Test/Zone')
  215. dti.offset :o1, -17900, 0, :TESTLMT
  216. dti.offset :o2, -18000, 0, :TEST
  217. o1 = TimezoneOffsetInfo.new(-17900, 0, :TESTLMT)
  218. assert_equal([TimezonePeriod.new(nil, nil, o1)], dti.periods_for_local(DateTime.new(2005,1,1,0,0,0)))
  219. assert_equal([TimezonePeriod.new(nil, nil, o1)], dti.periods_for_local(Time.utc(2005,1,1,0,0,0)))
  220. assert_equal([TimezonePeriod.new(nil, nil, o1)], dti.periods_for_local(Time.utc(2005,1,1,0,0,0).to_i))
  221. end
  222. def test_periods_for_local_no_offsets
  223. dti = DataTimezoneInfo.new('Test/Zone')
  224. assert_raises(NoOffsetsDefined) { dti.periods_for_local(DateTime.new(2005,1,1,0,0,0)) }
  225. assert_raises(NoOffsetsDefined) { dti.periods_for_local(Time.utc(2005,1,1,0,0,0)) }
  226. assert_raises(NoOffsetsDefined) { dti.periods_for_local(Time.utc(2005,1,1,0,0,0).to_i) }
  227. end
  228. end