PageRenderTime 33ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/ohimmelreich/asalia-training
Ruby | 114 lines | 85 code | 19 blank | 10 comment | 0 complexity | 337a09da3a8ac31e0da185988077eed2 MD5 | raw file
  1. $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
  2. require 'test/unit'
  3. require 'tzinfo'
  4. include TZInfo
  5. class TCTimezoneMelbourne < Test::Unit::TestCase
  6. def test_2004
  7. #Australia/Melbourne Sat Mar 27 15:59:59 2004 UTC = Sun Mar 28 02:59:59 2004 EST isdst=1 gmtoff=39600
  8. #Australia/Melbourne Sat Mar 27 16:00:00 2004 UTC = Sun Mar 28 02:00:00 2004 EST isdst=0 gmtoff=36000
  9. #Australia/Melbourne Sat Oct 30 15:59:59 2004 UTC = Sun Oct 31 01:59:59 2004 EST isdst=0 gmtoff=36000
  10. #Australia/Melbourne Sat Oct 30 16:00:00 2004 UTC = Sun Oct 31 03:00:00 2004 EST isdst=1 gmtoff=39600
  11. tz = Timezone.get('Australia/Melbourne')
  12. assert_equal(DateTime.new(2004,3,28,2,59,59), tz.utc_to_local(DateTime.new(2004,3,27,15,59,59)))
  13. assert_equal(DateTime.new(2004,3,28,2,0,0), tz.utc_to_local(DateTime.new(2004,3,27,16,0,0)))
  14. assert_equal(DateTime.new(2004,10,31,1,59,59), tz.utc_to_local(DateTime.new(2004,10,30,15,59,59)))
  15. assert_equal(DateTime.new(2004,10,31,3,0,0), tz.utc_to_local(DateTime.new(2004,10,30,16,0,0)))
  16. assert_equal(DateTime.new(2004,3,27,15,59,59), tz.local_to_utc(DateTime.new(2004,3,28,2,59,59), true))
  17. assert_equal(DateTime.new(2004,3,27,16,59,59), tz.local_to_utc(DateTime.new(2004,3,28,2,59,59), false))
  18. assert_equal(DateTime.new(2004,3,27,15,0,0), tz.local_to_utc(DateTime.new(2004,3,28,2,0,0), true))
  19. assert_equal(DateTime.new(2004,3,27,16,0,0), tz.local_to_utc(DateTime.new(2004,3,28,2,0,0), false))
  20. assert_equal(DateTime.new(2004,10,30,15,59,59), tz.local_to_utc(DateTime.new(2004,10,31,1,59,59)))
  21. assert_equal(DateTime.new(2004,10,30,16,0,0), tz.local_to_utc(DateTime.new(2004,10,31,3,0,0)))
  22. assert_raises(PeriodNotFound) { tz.local_to_utc(DateTime.new(2004,10,31,2,0,0)) }
  23. assert_raises(AmbiguousTime) { tz.local_to_utc(DateTime.new(2004,3,28,2,0,0)) }
  24. assert_equal(:EST, tz.period_for_utc(DateTime.new(2004,3,27,15,59,59)).zone_identifier)
  25. assert_equal(:EST, tz.period_for_utc(DateTime.new(2004,3,27,16,0,0)).zone_identifier)
  26. assert_equal(:EST, tz.period_for_utc(DateTime.new(2004,10,30,15,59,59)).zone_identifier)
  27. assert_equal(:EST, tz.period_for_utc(DateTime.new(2004,10,30,16,0,0)).zone_identifier)
  28. assert_equal(:EST, tz.period_for_local(DateTime.new(2004,3,28,2,59,59), true).zone_identifier)
  29. assert_equal(:EST, tz.period_for_local(DateTime.new(2004,3,28,2,59,59), false).zone_identifier)
  30. assert_equal(:EST, tz.period_for_local(DateTime.new(2004,3,28,2,0,0), true).zone_identifier)
  31. assert_equal(:EST, tz.period_for_local(DateTime.new(2004,3,28,2,0,0), false).zone_identifier)
  32. assert_equal(:EST, tz.period_for_local(DateTime.new(2004,10,31,1,59,59)).zone_identifier)
  33. assert_equal(:EST, tz.period_for_local(DateTime.new(2004,10,31,3,0,0)).zone_identifier)
  34. assert_equal(39600, tz.period_for_utc(DateTime.new(2004,3,27,15,59,59)).utc_total_offset)
  35. assert_equal(36000, tz.period_for_utc(DateTime.new(2004,3,27,16,0,0)).utc_total_offset)
  36. assert_equal(36000, tz.period_for_utc(DateTime.new(2004,10,30,15,59,59)).utc_total_offset)
  37. assert_equal(39600, tz.period_for_utc(DateTime.new(2004,10,30,16,0,0)).utc_total_offset)
  38. assert_equal(39600, tz.period_for_local(DateTime.new(2004,3,28,2,59,59), true).utc_total_offset)
  39. assert_equal(36000, tz.period_for_local(DateTime.new(2004,3,28,2,59,59), false).utc_total_offset)
  40. assert_equal(39600, tz.period_for_local(DateTime.new(2004,3,28,2,0,0), true).utc_total_offset)
  41. assert_equal(36000, tz.period_for_local(DateTime.new(2004,3,28,2,0,0), false).utc_total_offset)
  42. assert_equal(36000, tz.period_for_local(DateTime.new(2004,10,31,1,59,59)).utc_total_offset)
  43. assert_equal(39600, tz.period_for_local(DateTime.new(2004,10,31,3,0,0)).utc_total_offset)
  44. end
  45. def test_1942
  46. #Australia/Melbourne Sat Mar 28 14:59:59 1942 UTC = Sun Mar 29 01:59:59 1942 EST isdst=1 gmtoff=39600
  47. #Australia/Melbourne Sat Mar 28 15:00:00 1942 UTC = Sun Mar 29 01:00:00 1942 EST isdst=0 gmtoff=36000
  48. #Australia/Melbourne Sat Sep 26 15:59:59 1942 UTC = Sun Sep 27 01:59:59 1942 EST isdst=0 gmtoff=36000
  49. #Australia/Melbourne Sat Sep 26 16:00:00 1942 UTC = Sun Sep 27 03:00:00 1942 EST isdst=1 gmtoff=39600
  50. tz = Timezone.get('Australia/Melbourne')
  51. assert_equal(DateTime.new(1942,3,29,1,59,59), tz.utc_to_local(DateTime.new(1942,3,28,14,59,59)))
  52. assert_equal(DateTime.new(1942,3,29,1,0,0), tz.utc_to_local(DateTime.new(1942,3,28,15,0,0)))
  53. assert_equal(DateTime.new(1942,9,27,1,59,59), tz.utc_to_local(DateTime.new(1942,9,26,15,59,59)))
  54. assert_equal(DateTime.new(1942,9,27,3,0,0), tz.utc_to_local(DateTime.new(1942,9,26,16,0,0)))
  55. assert_equal(DateTime.new(1942,3,28,14,59,59), tz.local_to_utc(DateTime.new(1942,3,29,1,59,59), true))
  56. assert_equal(DateTime.new(1942,3,28,15,59,59), tz.local_to_utc(DateTime.new(1942,3,29,1,59,59), false))
  57. assert_equal(DateTime.new(1942,3,28,14,0,0), tz.local_to_utc(DateTime.new(1942,3,29,1,0,0), true))
  58. assert_equal(DateTime.new(1942,3,28,15,0,0), tz.local_to_utc(DateTime.new(1942,3,29,1,0,0), false))
  59. assert_equal(DateTime.new(1942,9,26,15,59,59), tz.local_to_utc(DateTime.new(1942,9,27,1,59,59)))
  60. assert_equal(DateTime.new(1942,9,26,16,0,0), tz.local_to_utc(DateTime.new(1942,9,27,3,0,0)))
  61. assert_raises(PeriodNotFound) { tz.local_to_utc(DateTime.new(1942,9,27,2,0,0)) }
  62. assert_raises(AmbiguousTime) { tz.local_to_utc(DateTime.new(1942,3,29,1,0,0)) }
  63. assert_equal(:EST, tz.period_for_utc(DateTime.new(1942,3,28,14,59,59)).zone_identifier)
  64. assert_equal(:EST, tz.period_for_utc(DateTime.new(1942,3,28,15,0,0)).zone_identifier)
  65. assert_equal(:EST, tz.period_for_utc(DateTime.new(1942,9,26,15,59,59)).zone_identifier)
  66. assert_equal(:EST, tz.period_for_utc(DateTime.new(1942,9,26,16,0,0)).zone_identifier)
  67. assert_equal(:EST, tz.period_for_local(DateTime.new(1942,3,29,1,59,59), true).zone_identifier)
  68. assert_equal(:EST, tz.period_for_local(DateTime.new(1942,3,29,1,59,59), false).zone_identifier)
  69. assert_equal(:EST, tz.period_for_local(DateTime.new(1942,3,29,1,0,0), true).zone_identifier)
  70. assert_equal(:EST, tz.period_for_local(DateTime.new(1942,3,29,1,0,0), false).zone_identifier)
  71. assert_equal(:EST, tz.period_for_local(DateTime.new(1942,9,27,1,59,59)).zone_identifier)
  72. assert_equal(:EST, tz.period_for_local(DateTime.new(1942,9,27,3,0,0)).zone_identifier)
  73. assert_equal(39600, tz.period_for_utc(DateTime.new(1942,3,28,14,59,59)).utc_total_offset)
  74. assert_equal(36000, tz.period_for_utc(DateTime.new(1942,3,28,15,0,0)).utc_total_offset)
  75. assert_equal(36000, tz.period_for_utc(DateTime.new(1942,9,26,15,59,59)).utc_total_offset)
  76. assert_equal(39600, tz.period_for_utc(DateTime.new(1942,9,26,16,0,0)).utc_total_offset)
  77. assert_equal(39600, tz.period_for_local(DateTime.new(1942,3,29,1,59,59), true).utc_total_offset)
  78. assert_equal(36000, tz.period_for_local(DateTime.new(1942,3,29,1,59,59), false).utc_total_offset)
  79. assert_equal(39600, tz.period_for_local(DateTime.new(1942,3,29,1,0,0), true).utc_total_offset)
  80. assert_equal(36000, tz.period_for_local(DateTime.new(1942,3,29,1,0,0), false).utc_total_offset)
  81. assert_equal(36000, tz.period_for_local(DateTime.new(1942,9,27,1,59,59)).utc_total_offset)
  82. assert_equal(39600, tz.period_for_local(DateTime.new(1942,9,27,3,0,0)).utc_total_offset)
  83. end
  84. def test_time_boundary
  85. #Australia/Melbourne Sat Mar 25 15:00:00 1944 UTC = Sun Mar 26 01:00:00 1944 EST isdst=0 gmtoff=36000
  86. #Australia/Melbourne Sat Oct 30 15:59:59 1971 UTC = Sun Oct 31 01:59:59 1971 EST isdst=0 gmtoff=36000
  87. tz = Timezone.get('Australia/Melbourne')
  88. assert_equal(DateTime.new(1970,1,1,10,0,0), tz.utc_to_local(DateTime.new(1970,1,1,0,0,0)))
  89. assert_equal(DateTime.new(1970,1,1,0,0,0), tz.local_to_utc(DateTime.new(1970,1,1,10,0,0)))
  90. assert_equal(Time.utc(1970,1,1,10,0,0), tz.utc_to_local(Time.utc(1970,1,1,0,0,0)))
  91. assert_equal(Time.utc(1970,1,1,0,0,0), tz.local_to_utc(Time.utc(1970,1,1,10,0,0)))
  92. assert_equal(36000, tz.utc_to_local(0))
  93. assert_equal(0, tz.local_to_utc(36000))
  94. end
  95. end