AddTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 AddTest extends TestFixture
  12. {
  13. public function testAddYearsPositive()
  14. {
  15. $this->assertSame(1976, Carbon::createFromDate(1975)->addYears(1)->year);
  16. }
  17. public function testAddYearsZero()
  18. {
  19. $this->assertSame(1975, Carbon::createFromDate(1975)->addYears(0)->year);
  20. }
  21. public function testAddYearsNegative()
  22. {
  23. $this->assertSame(1974, Carbon::createFromDate(1975)->addYears(-1)->year);
  24. }
  25. public function testAddYear()
  26. {
  27. $this->assertSame(1976, Carbon::createFromDate(1975)->addYear()->year);
  28. }
  29. public function testAddMonthsPositive()
  30. {
  31. $this->assertSame(1, Carbon::createFromDate(1975, 12)->addMonths(1)->month);
  32. }
  33. public function testAddMonthsZero()
  34. {
  35. $this->assertSame(12, Carbon::createFromDate(1975, 12)->addMonths(0)->month);
  36. }
  37. public function testAddMonthsNegative()
  38. {
  39. $this->assertSame(11, Carbon::createFromDate(1975, 12, 1)->addMonths(-1)->month);
  40. }
  41. public function testAddMonth()
  42. {
  43. $this->assertSame(1, Carbon::createFromDate(1975, 12)->addMonth()->month);
  44. }
  45. public function testAddMonthWithOverflow()
  46. {
  47. $this->assertSame(3, Carbon::createFromDate(2012, 1, 31)->addMonth()->month);
  48. }
  49. public function testAddDaysPositive()
  50. {
  51. $this->assertSame(1, Carbon::createFromDate(1975, 5, 31)->addDays(1)->day);
  52. }
  53. public function testAddDaysZero()
  54. {
  55. $this->assertSame(31, Carbon::createFromDate(1975, 5, 31)->addDays(0)->day);
  56. }
  57. public function testAddDaysNegative()
  58. {
  59. $this->assertSame(30, Carbon::createFromDate(1975, 5, 31)->addDays(-1)->day);
  60. }
  61. public function testAddDay()
  62. {
  63. $this->assertSame(1, Carbon::createFromDate(1975, 5, 31)->addDay()->day);
  64. }
  65. public function testAddWeekdaysPositive()
  66. {
  67. $this->assertSame(17, Carbon::createFromDate(2012, 1, 4)->addWeekdays(9)->day);
  68. }
  69. public function testAddWeekdaysZero()
  70. {
  71. $this->assertSame(4, Carbon::createFromDate(2012, 1, 4)->addWeekdays(0)->day);
  72. }
  73. public function testAddWeekdaysNegative()
  74. {
  75. $this->assertSame(18, Carbon::createFromDate(2012, 1, 31)->addWeekdays(-9)->day);
  76. }
  77. public function testAddWeekday()
  78. {
  79. $this->assertSame(9, Carbon::createFromDate(2012, 1, 6)->addWeekday()->day);
  80. }
  81. public function testAddWeeksPositive()
  82. {
  83. $this->assertSame(28, Carbon::createFromDate(1975, 5, 21)->addWeeks(1)->day);
  84. }
  85. public function testAddWeeksZero()
  86. {
  87. $this->assertSame(21, Carbon::createFromDate(1975, 5, 21)->addWeeks(0)->day);
  88. }
  89. public function testAddWeeksNegative()
  90. {
  91. $this->assertSame(14, Carbon::createFromDate(1975, 5, 21)->addWeeks(-1)->day);
  92. }
  93. public function testAddWeek()
  94. {
  95. $this->assertSame(28, Carbon::createFromDate(1975, 5, 21)->addWeek()->day);
  96. }
  97. public function testAddHoursPositive()
  98. {
  99. $this->assertSame(1, Carbon::createFromTime(0)->addHours(1)->hour);
  100. }
  101. public function testAddHoursZero()
  102. {
  103. $this->assertSame(0, Carbon::createFromTime(0)->addHours(0)->hour);
  104. }
  105. public function testAddHoursNegative()
  106. {
  107. $this->assertSame(23, Carbon::createFromTime(0)->addHours(-1)->hour);
  108. }
  109. public function testAddHour()
  110. {
  111. $this->assertSame(1, Carbon::createFromTime(0)->addHour()->hour);
  112. }
  113. public function testAddMinutesPositive()
  114. {
  115. $this->assertSame(1, Carbon::createFromTime(0, 0)->addMinutes(1)->minute);
  116. }
  117. public function testAddMinutesZero()
  118. {
  119. $this->assertSame(0, Carbon::createFromTime(0, 0)->addMinutes(0)->minute);
  120. }
  121. public function testAddMinutesNegative()
  122. {
  123. $this->assertSame(59, Carbon::createFromTime(0, 0)->addMinutes(-1)->minute);
  124. }
  125. public function testAddMinute()
  126. {
  127. $this->assertSame(1, Carbon::createFromTime(0, 0)->addMinute()->minute);
  128. }
  129. public function testAddSecondsPositive()
  130. {
  131. $this->assertSame(1, Carbon::createFromTime(0, 0, 0)->addSeconds(1)->second);
  132. }
  133. public function testAddSecondsZero()
  134. {
  135. $this->assertSame(0, Carbon::createFromTime(0, 0, 0)->addSeconds(0)->second);
  136. }
  137. public function testAddSecondsNegative()
  138. {
  139. $this->assertSame(59, Carbon::createFromTime(0, 0, 0)->addSeconds(-1)->second);
  140. }
  141. public function testAddSecond()
  142. {
  143. $this->assertSame(1, Carbon::createFromTime(0, 0, 0)->addSecond()->second);
  144. }
  145. }