IsTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 IsTest extends TestFixture
  12. {
  13. public function testIsWeekdayTrue()
  14. {
  15. $this->assertTrue(Carbon::createFromDate(2012, 1, 2)->isWeekday());
  16. }
  17. public function testIsWeekdayFalse()
  18. {
  19. $this->assertFalse(Carbon::createFromDate(2012, 1, 1)->isWeekday());
  20. }
  21. public function testIsWeekendTrue()
  22. {
  23. $this->assertTrue(Carbon::createFromDate(2012, 1, 1)->isWeekend());
  24. }
  25. public function testIsWeekendFalse()
  26. {
  27. $this->assertFalse(Carbon::createFromDate(2012, 1, 2)->isWeekend());
  28. }
  29. public function testIsYesterdayTrue()
  30. {
  31. $this->assertTrue(Carbon::now()->subDay()->isYesterday());
  32. }
  33. public function testIsYesterdayFalseWithToday()
  34. {
  35. $this->assertFalse(Carbon::now()->endOfDay()->isYesterday());
  36. }
  37. public function testIsYesterdayFalseWith2Days()
  38. {
  39. $this->assertFalse(Carbon::now()->subDays(2)->startOfDay()->isYesterday());
  40. }
  41. public function testIsTodayTrue()
  42. {
  43. $this->assertTrue(Carbon::now()->isToday());
  44. }
  45. public function testIsTodayFalseWithYesterday()
  46. {
  47. $this->assertFalse(Carbon::now()->subDay()->endOfDay()->isToday());
  48. }
  49. public function testIsTodayFalseWithTomorrow()
  50. {
  51. $this->assertFalse(Carbon::now()->addDay()->startOfDay()->isToday());
  52. }
  53. public function testIsTodayWithTimezone()
  54. {
  55. $this->assertTrue(Carbon::now('Asia/Tokyo')->isToday());
  56. }
  57. public function testIsTomorrowTrue()
  58. {
  59. $this->assertTrue(Carbon::now()->addDay()->isTomorrow());
  60. }
  61. public function testIsTomorrowFalseWithToday()
  62. {
  63. $this->assertFalse(Carbon::now()->endOfDay()->isTomorrow());
  64. }
  65. public function testIsTomorrowFalseWith2Days()
  66. {
  67. $this->assertFalse(Carbon::now()->addDays(2)->startOfDay()->isTomorrow());
  68. }
  69. public function testIsFutureTrue()
  70. {
  71. $this->assertTrue(Carbon::now()->addSecond()->isFuture());
  72. }
  73. public function testIsFutureFalse()
  74. {
  75. $this->assertFalse(Carbon::now()->isFuture());
  76. }
  77. public function testIsFutureFalseInThePast()
  78. {
  79. $this->assertFalse(Carbon::now()->subSecond()->isFuture());
  80. }
  81. public function testIsPastTrue()
  82. {
  83. $this->assertTrue(Carbon::now()->subSecond()->isPast());
  84. }
  85. public function testIsPast()
  86. {
  87. $this->assertFalse(Carbon::now()->addSecond()->isPast());
  88. }
  89. }