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

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

https://bitbucket.org/ohimmelreich/asalia-training
Ruby | 422 lines | 375 code | 47 blank | 0 comment | 0 complexity | 104aeb1948bae299df78b186d02baab4 MD5 | raw file
  1. $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
  2. require 'test/unit'
  3. require 'tzinfo'
  4. include TZInfo
  5. class TCTimeOrDateTime < Test::Unit::TestCase
  6. def test_initialize_time
  7. TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3))
  8. end
  9. def test_initialize_time_local
  10. tdt = TimeOrDateTime.new(Time.local(2006, 3, 24, 15, 32, 3))
  11. assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), tdt.to_time)
  12. assert_equal('UTC', tdt.to_time.zone)
  13. end
  14. def test_initialize_datetime_offset
  15. tdt = TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3).new_offset(Rational(5, 24)))
  16. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), tdt.to_datetime)
  17. assert_equal(0, tdt.to_datetime.offset)
  18. end
  19. def test_initialize_datetime
  20. TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3))
  21. end
  22. def test_initialize_int
  23. TimeOrDateTime.new(1143214323)
  24. end
  25. def test_initialize_string
  26. TimeOrDateTime.new('1143214323')
  27. end
  28. def test_to_time
  29. assert_equal(Time.utc(2006, 3, 24, 15, 32, 3),
  30. TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).to_time)
  31. assert_equal(Time.utc(2006, 3, 24, 15, 32, 3),
  32. TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).to_time)
  33. assert_equal(Time.utc(2006, 3, 24, 15, 32, 3),
  34. TimeOrDateTime.new(1143214323).to_time)
  35. assert_equal(Time.utc(2006, 3, 24, 15, 32, 3),
  36. TimeOrDateTime.new('1143214323').to_time)
  37. end
  38. def test_to_datetime
  39. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3),
  40. TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).to_datetime)
  41. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3),
  42. TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).to_datetime)
  43. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3),
  44. TimeOrDateTime.new(1143214323).to_datetime)
  45. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3),
  46. TimeOrDateTime.new('1143214323').to_datetime)
  47. end
  48. def test_to_i
  49. assert_equal(1143214323,
  50. TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).to_i)
  51. assert_equal(1143214323,
  52. TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).to_i)
  53. assert_equal(1143214323,
  54. TimeOrDateTime.new(1143214323).to_i)
  55. assert_equal(1143214323,
  56. TimeOrDateTime.new('1143214323').to_i)
  57. end
  58. def test_to_orig
  59. assert_equal(Time.utc(2006, 3, 24, 15, 32, 3),
  60. TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).to_orig)
  61. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3),
  62. TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).to_orig)
  63. assert_equal(1143214323,
  64. TimeOrDateTime.new(1143214323).to_orig)
  65. assert_equal(1143214323,
  66. TimeOrDateTime.new('1143214323').to_orig)
  67. end
  68. def test_to_s
  69. assert_equal("Time: #{Time.utc(2006, 3, 24, 15, 32, 3).to_s}",
  70. TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).to_s)
  71. assert_equal("DateTime: #{DateTime.new(2006, 3, 24, 15, 32, 3)}",
  72. TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).to_s)
  73. assert_equal('Timestamp: 1143214323',
  74. TimeOrDateTime.new(1143214323).to_s)
  75. assert_equal('Timestamp: 1143214323',
  76. TimeOrDateTime.new('1143214323').to_s)
  77. end
  78. def test_year
  79. assert_equal(2006, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).year)
  80. assert_equal(2006, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).year)
  81. assert_equal(2006, TimeOrDateTime.new(1143214323).year)
  82. end
  83. def test_mon
  84. assert_equal(3, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).mon)
  85. assert_equal(3, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).mon)
  86. assert_equal(3, TimeOrDateTime.new(1143214323).mon)
  87. end
  88. def test_month
  89. assert_equal(3, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).month)
  90. assert_equal(3, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).month)
  91. assert_equal(3, TimeOrDateTime.new(1143214323).month)
  92. end
  93. def test_mday
  94. assert_equal(24, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).mday)
  95. assert_equal(24, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).mday)
  96. assert_equal(24, TimeOrDateTime.new(1143214323).mday)
  97. end
  98. def test_day
  99. assert_equal(24, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).day)
  100. assert_equal(24, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).day)
  101. assert_equal(24, TimeOrDateTime.new(1143214323).day)
  102. end
  103. def test_hour
  104. assert_equal(15, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).hour)
  105. assert_equal(15, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).hour)
  106. assert_equal(15, TimeOrDateTime.new(1143214323).hour)
  107. end
  108. def test_min
  109. assert_equal(32, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).min)
  110. assert_equal(32, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).min)
  111. assert_equal(32, TimeOrDateTime.new(1143214323).min)
  112. end
  113. def test_sec
  114. assert_equal(3, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).sec)
  115. assert_equal(3, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).sec)
  116. assert_equal(3, TimeOrDateTime.new(1143214323).sec)
  117. end
  118. def test_compare_timeordatetime_time
  119. assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 4)))
  120. assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2007, 3, 24, 15, 32, 3)))
  121. assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)))
  122. assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 2)))
  123. assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2005, 3, 24, 15, 32, 3)))
  124. assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 4)))
  125. assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2007, 3, 24, 15, 32, 3)))
  126. assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)))
  127. assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 2)))
  128. assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2005, 3, 24, 15, 32, 3)))
  129. assert_equal(-1, TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)))
  130. assert_equal(1, TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)))
  131. assert_equal(-1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 4)))
  132. assert_equal(-1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(Time.utc(2007, 3, 24, 15, 32, 3)))
  133. assert_equal(0, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)))
  134. assert_equal(1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 2)))
  135. assert_equal(1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(Time.utc(2005, 3, 24, 15, 32, 3)))
  136. end
  137. def test_compare_timeordatetime_datetime
  138. assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 4)))
  139. assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)))
  140. assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)))
  141. assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 2)))
  142. assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)))
  143. assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 4)))
  144. assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)))
  145. assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)))
  146. assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 2)))
  147. assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)))
  148. assert_equal(-1, TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)))
  149. assert_equal(1, TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)))
  150. assert_equal(-1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 4)))
  151. assert_equal(-1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)))
  152. assert_equal(0, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)))
  153. assert_equal(1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 2)))
  154. assert_equal(1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)))
  155. end
  156. def test_compare_timeordatetime_timestamp
  157. assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214324))
  158. assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1174750323))
  159. assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214323))
  160. assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214322))
  161. assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1111678323))
  162. assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214324))
  163. assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1174750323))
  164. assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214323))
  165. assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214322))
  166. assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1111678323))
  167. assert_equal(-1, TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214323))
  168. assert_equal(1, TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)) <=> TimeOrDateTime.new(1143214323))
  169. assert_equal(-1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(1143214324))
  170. assert_equal(-1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(1174750323))
  171. assert_equal(0, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(1143214323))
  172. assert_equal(1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(1143214322))
  173. assert_equal(1, TimeOrDateTime.new(1143214323) <=> TimeOrDateTime.new(1111678323))
  174. end
  175. def test_compare_time
  176. assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 4))
  177. assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2007, 3, 24, 15, 32, 3))
  178. assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 3))
  179. assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 2))
  180. assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2005, 3, 24, 15, 32, 3))
  181. assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 4))
  182. assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2007, 3, 24, 15, 32, 3))
  183. assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 3))
  184. assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 2))
  185. assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> Time.utc(2005, 3, 24, 15, 32, 3))
  186. assert_equal(-1, TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 3))
  187. assert_equal(1, TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)) <=> Time.utc(2006, 3, 24, 15, 32, 3))
  188. assert_equal(-1, TimeOrDateTime.new(1143214323) <=> Time.utc(2006, 3, 24, 15, 32, 4))
  189. assert_equal(-1, TimeOrDateTime.new(1143214323) <=> Time.utc(2007, 3, 24, 15, 32, 3))
  190. assert_equal(0, TimeOrDateTime.new(1143214323) <=> Time.utc(2006, 3, 24, 15, 32, 3))
  191. assert_equal(1, TimeOrDateTime.new(1143214323) <=> Time.utc(2006, 3, 24, 15, 32, 2))
  192. assert_equal(1, TimeOrDateTime.new(1143214323) <=> Time.utc(2005, 3, 24, 15, 32, 3))
  193. end
  194. def test_compare_datetime
  195. assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 4))
  196. assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2040, 3, 24, 15, 32, 3))
  197. assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 3))
  198. assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 2))
  199. assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(1960, 3, 24, 15, 32, 3))
  200. assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 4))
  201. assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2040, 3, 24, 15, 32, 3))
  202. assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 3))
  203. assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 2))
  204. assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> DateTime.new(1960, 3, 24, 15, 32, 3))
  205. assert_equal(-1, TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 3))
  206. assert_equal(1, TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)) <=> DateTime.new(2006, 3, 24, 15, 32, 3))
  207. assert_equal(-1, TimeOrDateTime.new(1143214323) <=> DateTime.new(2006, 3, 24, 15, 32, 4))
  208. assert_equal(-1, TimeOrDateTime.new(1143214323) <=> DateTime.new(2040, 3, 24, 15, 32, 3))
  209. assert_equal(0, TimeOrDateTime.new(1143214323) <=> DateTime.new(2006, 3, 24, 15, 32, 3))
  210. assert_equal(1, TimeOrDateTime.new(1143214323) <=> DateTime.new(2006, 3, 24, 15, 32, 2))
  211. assert_equal(1, TimeOrDateTime.new(1143214323) <=> DateTime.new(1960, 3, 24, 15, 32, 3))
  212. end
  213. def test_compare_timestamp
  214. assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> 1143214324)
  215. assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> 1174750323)
  216. assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> 1143214323)
  217. assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> 1143214322)
  218. assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> 1111678323)
  219. assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> 1143214324)
  220. assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> 1174750323)
  221. assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> 1143214323)
  222. assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> 1143214322)
  223. assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> 1111678323)
  224. assert_equal(-1, TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)) <=> 1143214323)
  225. assert_equal(1, TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)) <=> 1143214323)
  226. assert_equal(-1, TimeOrDateTime.new(1143214323) <=> 1143214324)
  227. assert_equal(-1, TimeOrDateTime.new(1143214323) <=> 1174750323)
  228. assert_equal(0, TimeOrDateTime.new(1143214323) <=> 1143214323)
  229. assert_equal(1, TimeOrDateTime.new(1143214323) <=> 1143214322)
  230. assert_equal(1, TimeOrDateTime.new(1143214323) <=> 1111678323)
  231. end
  232. def test_compare_timestamp_str
  233. assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> '1143214324')
  234. assert_equal(-1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> '1174750323')
  235. assert_equal(0, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> '1143214323')
  236. assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> '1143214322')
  237. assert_equal(1, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) <=> '1111678323')
  238. assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> '1143214324')
  239. assert_equal(-1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> '1174750323')
  240. assert_equal(0, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> '1143214323')
  241. assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> '1143214322')
  242. assert_equal(1, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) <=> '1111678323')
  243. assert_equal(-1, TimeOrDateTime.new(DateTime.new(1960, 3, 24, 15, 32, 3)) <=> '1143214323')
  244. assert_equal(1, TimeOrDateTime.new(DateTime.new(2040, 3, 24, 15, 32, 3)) <=> '1143214323')
  245. assert_equal(-1, TimeOrDateTime.new(1143214323) <=> '1143214324')
  246. assert_equal(-1, TimeOrDateTime.new(1143214323) <=> '1174750323')
  247. assert_equal(0, TimeOrDateTime.new(1143214323) <=> '1143214323')
  248. assert_equal(1, TimeOrDateTime.new(1143214323) <=> '1143214322')
  249. assert_equal(1, TimeOrDateTime.new(1143214323) <=> '1111678323')
  250. end
  251. def test_eql
  252. assert_equal(true, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3))))
  253. assert_equal(false, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3))))
  254. assert_equal(false, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(1143214323)))
  255. assert_equal(false, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new('1143214323')))
  256. assert_equal(false, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 4))))
  257. assert_equal(false, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).eql?(Object.new))
  258. assert_equal(false, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3))))
  259. assert_equal(true, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3))))
  260. assert_equal(false, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(1143214323)))
  261. assert_equal(false, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new('1143214323')))
  262. assert_equal(false, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).eql?(TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 4))))
  263. assert_equal(false, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).eql?(Object.new))
  264. assert_equal(false, TimeOrDateTime.new(1143214323).eql?(TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3))))
  265. assert_equal(false, TimeOrDateTime.new(1143214323).eql?(TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3))))
  266. assert_equal(true, TimeOrDateTime.new(1143214323).eql?(TimeOrDateTime.new(1143214323)))
  267. assert_equal(true, TimeOrDateTime.new(1143214323).eql?(TimeOrDateTime.new('1143214323')))
  268. assert_equal(false, TimeOrDateTime.new(1143214323).eql?(TimeOrDateTime.new(1143214324)))
  269. assert_equal(false, TimeOrDateTime.new(1143214323).eql?(Object.new))
  270. end
  271. def test_hash
  272. assert_equal(Time.utc(2006, 3, 24, 15, 32, 3).hash, TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).hash)
  273. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3).hash, TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).hash)
  274. assert_equal(1143214323.hash, TimeOrDateTime.new(1143214323).hash)
  275. assert_equal(1143214323.hash, TimeOrDateTime.new('1143214323').hash)
  276. end
  277. def test_add
  278. assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) + 0).to_orig)
  279. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) + 0).to_orig)
  280. assert_equal(1143214323, (TimeOrDateTime.new(1143214323) + 0).to_orig)
  281. assert_equal(Time.utc(2006, 3, 24, 15, 32, 4), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) + 1).to_orig)
  282. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) + 1).to_orig)
  283. assert_equal(1143214324, (TimeOrDateTime.new(1143214323) + 1).to_orig)
  284. assert_equal(Time.utc(2006, 3, 24, 15, 32, 2), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) + (-1)).to_orig)
  285. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) + (-1)).to_orig)
  286. assert_equal(1143214322, (TimeOrDateTime.new(1143214323) + (-1)).to_orig)
  287. end
  288. def test_subtract
  289. assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) - 0).to_orig)
  290. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) - 0).to_orig)
  291. assert_equal(1143214323, (TimeOrDateTime.new(1143214323) - 0).to_orig)
  292. assert_equal(Time.utc(2006, 3, 24, 15, 32, 2), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) - 1).to_orig)
  293. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) - 1).to_orig)
  294. assert_equal(1143214322, (TimeOrDateTime.new(1143214323) - 1).to_orig)
  295. assert_equal(Time.utc(2006, 3, 24, 15, 32, 4), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) - (-1)).to_orig)
  296. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) - (-1)).to_orig)
  297. assert_equal(1143214324, (TimeOrDateTime.new(1143214323) - (-1)).to_orig)
  298. end
  299. def test_add_with_convert
  300. assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).add_with_convert(0).to_orig)
  301. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).add_with_convert(0).to_orig)
  302. assert_equal(1143214323, TimeOrDateTime.new(1143214323).add_with_convert(0).to_orig)
  303. assert_equal(Time.utc(2006, 3, 24, 15, 32, 4), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).add_with_convert(1).to_orig)
  304. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).add_with_convert(1).to_orig)
  305. assert_equal(1143214324, TimeOrDateTime.new(1143214323).add_with_convert(1).to_orig)
  306. assert_equal(Time.utc(2006, 3, 24, 15, 32, 2), TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).add_with_convert(-1).to_orig)
  307. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 2), TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).add_with_convert(-1).to_orig)
  308. assert_equal(1143214322, TimeOrDateTime.new(1143214323).add_with_convert(-1).to_orig)
  309. assert_equal(DateTime.new(1969, 12, 31, 23, 59, 59), TimeOrDateTime.new(Time.utc(1970, 1, 1, 0, 0, 0)).add_with_convert(-1).to_orig)
  310. assert_equal(DateTime.new(2038, 1, 19, 3, 14, 8), TimeOrDateTime.new(Time.utc(2038, 1, 19, 3, 14, 7)).add_with_convert(1).to_orig)
  311. end
  312. def test_wrap_time
  313. t = TimeOrDateTime.wrap(Time.utc(2006, 3, 24, 15, 32, 3))
  314. assert_instance_of(TimeOrDateTime, t)
  315. assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), t.to_orig)
  316. end
  317. def test_wrap_datetime
  318. t = TimeOrDateTime.wrap(DateTime.new(2006, 3, 24, 15, 32, 3))
  319. assert_instance_of(TimeOrDateTime, t)
  320. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), t.to_orig)
  321. end
  322. def test_wrap_timestamp
  323. t = TimeOrDateTime.wrap(1143214323)
  324. assert_instance_of(TimeOrDateTime, t)
  325. assert_equal(1143214323, t.to_orig)
  326. end
  327. def test_wrap_timestamp_str
  328. t = TimeOrDateTime.wrap('1143214323')
  329. assert_instance_of(TimeOrDateTime, t)
  330. assert_equal(1143214323, t.to_orig)
  331. end
  332. def test_wrap_timeordatetime
  333. t = TimeOrDateTime.new(1143214323)
  334. t2 = TimeOrDateTime.wrap(t)
  335. assert_same(t, t2)
  336. end
  337. def test_wrap_block_time
  338. assert_equal(Time.utc(2006, 3, 24, 15, 32, 4), TimeOrDateTime.wrap(Time.utc(2006, 3, 24, 15, 32, 3)) {|t|
  339. assert_instance_of(TimeOrDateTime, t)
  340. assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), t.to_orig)
  341. t + 1
  342. })
  343. end
  344. def test_wrap_block_datetime
  345. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4), TimeOrDateTime.wrap(DateTime.new(2006, 3, 24, 15, 32, 3)) {|t|
  346. assert_instance_of(TimeOrDateTime, t)
  347. assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), t.to_orig)
  348. t + 1
  349. })
  350. end
  351. def test_wrap_block_timestamp
  352. assert_equal(1143214324, TimeOrDateTime.wrap(1143214323) {|t|
  353. assert_instance_of(TimeOrDateTime, t)
  354. assert_equal(1143214323, t.to_orig)
  355. t + 1
  356. })
  357. end
  358. def test_wrap_block_timestamp_str
  359. assert_equal(1143214324, TimeOrDateTime.wrap('1143214323') {|t|
  360. assert_instance_of(TimeOrDateTime, t)
  361. assert_equal(1143214323, t.to_orig)
  362. t + 1
  363. })
  364. end
  365. def test_wrap_block_timeordatetime
  366. t1 = TimeOrDateTime.new(1143214323)
  367. t2 = TimeOrDateTime.wrap(t1) {|t|
  368. assert_same(t1, t)
  369. t + 1
  370. }
  371. assert t2
  372. assert_instance_of(TimeOrDateTime, t2)
  373. assert_equal(1143214324, t2.to_orig)
  374. end
  375. end