SubTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 SubTest extends TestFixture
  12. {
  13. public function testSubYearsPositive()
  14. {
  15. $this->assertSame(1974, Carbon::createFromDate(1975)->subYears(1)->year);
  16. }
  17. public function testSubYearsZero()
  18. {
  19. $this->assertSame(1975, Carbon::createFromDate(1975)->subYears(0)->year);
  20. }
  21. public function testSubYearsNegative()
  22. {
  23. $this->assertSame(1976, Carbon::createFromDate(1975)->subYears(-1)->year);
  24. }
  25. public function testSubYear()
  26. {
  27. $this->assertSame(1974, Carbon::createFromDate(1975)->subYear()->year);
  28. }
  29. public function testSubMonthsPositive()
  30. {
  31. $this->assertSame(12, Carbon::createFromDate(1975, 1, 1)->subMonths(1)->month);
  32. }
  33. public function testSubMonthsZero()
  34. {
  35. $this->assertSame(1, Carbon::createFromDate(1975, 1, 1)->subMonths(0)->month);
  36. }
  37. public function testSubMonthsNegative()
  38. {
  39. $this->assertSame(2, Carbon::createFromDate(1975, 1, 1)->subMonths(-1)->month);
  40. }
  41. public function testSubMonth()
  42. {
  43. $this->assertSame(12, Carbon::createFromDate(1975, 1, 1)->subMonth()->month);
  44. }
  45. public function testSubDaysPositive()
  46. {
  47. $this->assertSame(30, Carbon::createFromDate(1975, 5, 1)->subDays(1)->day);
  48. }
  49. public function testSubDaysZero()
  50. {
  51. $this->assertSame(1, Carbon::createFromDate(1975, 5, 1)->subDays(0)->day);
  52. }
  53. public function testSubDaysNegative()
  54. {
  55. $this->assertSame(2, Carbon::createFromDate(1975, 5, 1)->subDays(-1)->day);
  56. }
  57. public function testSubDay()
  58. {
  59. $this->assertSame(30, Carbon::createFromDate(1975, 5, 1)->subDay()->day);
  60. }
  61. public function testSubWeekdaysPositive()
  62. {
  63. $this->assertSame(22, Carbon::createFromDate(2012, 1, 4)->subWeekdays(9)->day);
  64. }
  65. public function testSubWeekdaysZero()
  66. {
  67. $this->assertSame(4, Carbon::createFromDate(2012, 1, 4)->subWeekdays(0)->day);
  68. }
  69. public function testSubWeekdaysNegative()
  70. {
  71. $this->assertSame(13, Carbon::createFromDate(2012, 1, 31)->subWeekdays(-9)->day);
  72. }
  73. public function testSubWeekday()
  74. {
  75. $this->assertSame(6, Carbon::createFromDate(2012, 1, 9)->subWeekday()->day);
  76. }
  77. public function testSubWeeksPositive()
  78. {
  79. $this->assertSame(14, Carbon::createFromDate(1975, 5, 21)->subWeeks(1)->day);
  80. }
  81. public function testSubWeeksZero()
  82. {
  83. $this->assertSame(21, Carbon::createFromDate(1975, 5, 21)->subWeeks(0)->day);
  84. }
  85. public function testSubWeeksNegative()
  86. {
  87. $this->assertSame(28, Carbon::createFromDate(1975, 5, 21)->subWeeks(-1)->day);
  88. }
  89. public function testSubWeek()
  90. {
  91. $this->assertSame(14, Carbon::createFromDate(1975, 5, 21)->subWeek()->day);
  92. }
  93. public function testSubHoursPositive()
  94. {
  95. $this->assertSame(23, Carbon::createFromTime(0)->subHours(1)->hour);
  96. }
  97. public function testSubHoursZero()
  98. {
  99. $this->assertSame(0, Carbon::createFromTime(0)->subHours(0)->hour);
  100. }
  101. public function testSubHoursNegative()
  102. {
  103. $this->assertSame(1, Carbon::createFromTime(0)->subHours(-1)->hour);
  104. }
  105. public function testSubHour()
  106. {
  107. $this->assertSame(23, Carbon::createFromTime(0)->subHour()->hour);
  108. }
  109. public function testSubMinutesPositive()
  110. {
  111. $this->assertSame(59, Carbon::createFromTime(0, 0)->subMinutes(1)->minute);
  112. }
  113. public function testSubMinutesZero()
  114. {
  115. $this->assertSame(0, Carbon::createFromTime(0, 0)->subMinutes(0)->minute);
  116. }
  117. public function testSubMinutesNegative()
  118. {
  119. $this->assertSame(1, Carbon::createFromTime(0, 0)->subMinutes(-1)->minute);
  120. }
  121. public function testSubMinute()
  122. {
  123. $this->assertSame(59, Carbon::createFromTime(0, 0)->subMinute()->minute);
  124. }
  125. public function testSubSecondsPositive()
  126. {
  127. $this->assertSame(59, Carbon::createFromTime(0, 0, 0)->subSeconds(1)->second);
  128. }
  129. public function testSubSecondsZero()
  130. {
  131. $this->assertSame(0, Carbon::createFromTime(0, 0, 0)->subSeconds(0)->second);
  132. }
  133. public function testSubSecondsNegative()
  134. {
  135. $this->assertSame(1, Carbon::createFromTime(0, 0, 0)->subSeconds(-1)->second);
  136. }
  137. public function testSubSecond()
  138. {
  139. $this->assertSame(59, Carbon::createFromTime(0, 0, 0)->subSecond()->second);
  140. }
  141. }