ComparisonTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /*
  3. * This file is part of the Carbon package.
  4. *
  5. * (c) Brian Nesbitt <brian@nesbot.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. use Carbon\Carbon;
  11. class ComparisonTest extends TestFixture
  12. {
  13. public function testEqualToTrue()
  14. {
  15. $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->eq(Carbon::createFromDate(2000, 1, 1)));
  16. }
  17. public function testEqualToFalse()
  18. {
  19. $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->eq(Carbon::createFromDate(2000, 1, 2)));
  20. }
  21. public function testEqualWithTimezoneTrue()
  22. {
  23. $this->assertTrue(Carbon::create(2000, 1, 1, 12, 0, 0, 'America/Toronto')->eq(Carbon::create(2000, 1, 1, 9, 0, 0, 'America/Vancouver')));
  24. }
  25. public function testEqualWithTimezoneFalse()
  26. {
  27. $this->assertFalse(Carbon::createFromDate(2000, 1, 1, 'America/Toronto')->eq(Carbon::createFromDate(2000, 1, 1, 'America/Vancouver')));
  28. }
  29. public function testNotEqualToTrue()
  30. {
  31. $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->ne(Carbon::createFromDate(2000, 1, 2)));
  32. }
  33. public function testNotEqualToFalse()
  34. {
  35. $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->ne(Carbon::createFromDate(2000, 1, 1)));
  36. }
  37. public function testNotEqualWithTimezone()
  38. {
  39. $this->assertTrue(Carbon::createFromDate(2000, 1, 1, 'America/Toronto')->ne(Carbon::createFromDate(2000, 1, 1, 'America/Vancouver')));
  40. }
  41. public function testGreaterThanTrue()
  42. {
  43. $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->gt(Carbon::createFromDate(1999, 12, 31)));
  44. }
  45. public function testGreaterThanFalse()
  46. {
  47. $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->gt(Carbon::createFromDate(2000, 1, 2)));
  48. }
  49. public function testGreaterThanWithTimezoneTrue()
  50. {
  51. $dt1 = Carbon::create(2000, 1, 1, 12, 0, 0, 'America/Toronto');
  52. $dt2 = Carbon::create(2000, 1, 1, 8, 59, 59, 'America/Vancouver');
  53. $this->assertTrue($dt1->gt($dt2));
  54. }
  55. public function testGreaterThanWithTimezoneFalse()
  56. {
  57. $dt1 = Carbon::create(2000, 1, 1, 12, 0, 0, 'America/Toronto');
  58. $dt2 = Carbon::create(2000, 1, 1, 9, 0, 1, 'America/Vancouver');
  59. $this->assertFalse($dt1->gt($dt2));
  60. }
  61. public function testGreaterThanOrEqualTrue()
  62. {
  63. $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->gte(Carbon::createFromDate(1999, 12, 31)));
  64. }
  65. public function testGreaterThanOrEqualTrueEqual()
  66. {
  67. $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->gte(Carbon::createFromDate(2000, 1, 1)));
  68. }
  69. public function testGreaterThanOrEqualFalse()
  70. {
  71. $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->gte(Carbon::createFromDate(2000, 1, 2)));
  72. }
  73. public function testLessThanTrue()
  74. {
  75. $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->lt(Carbon::createFromDate(2000, 1, 2)));
  76. }
  77. public function testLessThanFalse()
  78. {
  79. $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->lt(Carbon::createFromDate(1999, 12, 31)));
  80. }
  81. public function testLessThanOrEqualTrue()
  82. {
  83. $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->lte(Carbon::createFromDate(2000, 1, 2)));
  84. }
  85. public function testLessThanOrEqualTrueEqual()
  86. {
  87. $this->assertTrue(Carbon::createFromDate(2000, 1, 1)->lte(Carbon::createFromDate(2000, 1, 1)));
  88. }
  89. public function testLessThanOrEqualFalse()
  90. {
  91. $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->lte(Carbon::createFromDate(1999, 12, 31)));
  92. }
  93. public function testBetweenEqualTrue()
  94. {
  95. $this->assertTrue(Carbon::createFromDate(2000, 1, 15)->between(Carbon::createFromDate(2000, 1, 1), Carbon::createFromDate(2000, 1, 31), true));
  96. }
  97. public function testBetweenNotEqualTrue()
  98. {
  99. $this->assertTrue(Carbon::createFromDate(2000, 1, 15)->between(Carbon::createFromDate(2000, 1, 1), Carbon::createFromDate(2000, 1, 31), false));
  100. }
  101. public function testBetweenEqualFalse()
  102. {
  103. $this->assertFalse(Carbon::createFromDate(1999, 12, 31)->between(Carbon::createFromDate(2000, 1, 1), Carbon::createFromDate(2000, 1, 31), true));
  104. }
  105. public function testBetweenNotEqualFalse()
  106. {
  107. $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->between(Carbon::createFromDate(2000, 1, 1), Carbon::createFromDate(2000, 1, 31), false));
  108. }
  109. public function testBetweenEqualSwitchTrue()
  110. {
  111. $this->assertTrue(Carbon::createFromDate(2000, 1, 15)->between(Carbon::createFromDate(2000, 1, 31), Carbon::createFromDate(2000, 1, 1), true));
  112. }
  113. public function testBetweenNotEqualSwitchTrue()
  114. {
  115. $this->assertTrue(Carbon::createFromDate(2000, 1, 15)->between(Carbon::createFromDate(2000, 1, 31), Carbon::createFromDate(2000, 1, 1), false));
  116. }
  117. public function testBetweenEqualSwitchFalse()
  118. {
  119. $this->assertFalse(Carbon::createFromDate(1999, 12, 31)->between(Carbon::createFromDate(2000, 1, 31), Carbon::createFromDate(2000, 1, 1), true));
  120. }
  121. public function testBetweenNotEqualSwitchFalse()
  122. {
  123. $this->assertFalse(Carbon::createFromDate(2000, 1, 1)->between(Carbon::createFromDate(2000, 1, 31), Carbon::createFromDate(2000, 1, 1), false));
  124. }
  125. }