No Description

AddTest.php 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 testAddMonthsNoOverflowPositive()
  50. {
  51. $this->assertSame('2012-02-29', Carbon::createFromDate(2012, 1, 31)->addMonthNoOverflow()->toDateString());
  52. $this->assertSame('2012-03-31', Carbon::createFromDate(2012, 1, 31)->addMonthsNoOverflow(2)->toDateString());
  53. $this->assertSame('2012-03-29', Carbon::createFromDate(2012, 2, 29)->addMonthNoOverflow()->toDateString());
  54. $this->assertSame('2012-02-29', Carbon::createFromDate(2011, 12, 31)->addMonthsNoOverflow(2)->toDateString());
  55. }
  56. public function testAddMonthsNoOverflowZero()
  57. {
  58. $this->assertSame(12, Carbon::createFromDate(1975, 12)->addMonths(0)->month);
  59. }
  60. public function testAddMonthsNoOverflowNegative()
  61. {
  62. $this->assertSame('2012-01-29', Carbon::createFromDate(2012, 2, 29)->addMonthsNoOverflow(-1)->toDateString());
  63. $this->assertSame('2012-01-31', Carbon::createFromDate(2012, 3, 31)->addMonthsNoOverflow(-2)->toDateString());
  64. $this->assertSame('2012-02-29', Carbon::createFromDate(2012, 3, 31)->addMonthsNoOverflow(-1)->toDateString());
  65. $this->assertSame('2011-12-31', Carbon::createFromDate(2012, 1, 31)->addMonthsNoOverflow(-1)->toDateString());
  66. }
  67. public function testAddDaysPositive()
  68. {
  69. $this->assertSame(1, Carbon::createFromDate(1975, 5, 31)->addDays(1)->day);
  70. }
  71. public function testAddDaysZero()
  72. {
  73. $this->assertSame(31, Carbon::createFromDate(1975, 5, 31)->addDays(0)->day);
  74. }
  75. public function testAddDaysNegative()
  76. {
  77. $this->assertSame(30, Carbon::createFromDate(1975, 5, 31)->addDays(-1)->day);
  78. }
  79. public function testAddDay()
  80. {
  81. $this->assertSame(1, Carbon::createFromDate(1975, 5, 31)->addDay()->day);
  82. }
  83. public function testAddWeekdaysPositive()
  84. {
  85. $this->assertSame(17, Carbon::createFromDate(2012, 1, 4)->addWeekdays(9)->day);
  86. }
  87. public function testAddWeekdaysZero()
  88. {
  89. $this->assertSame(4, Carbon::createFromDate(2012, 1, 4)->addWeekdays(0)->day);
  90. }
  91. public function testAddWeekdaysNegative()
  92. {
  93. $this->assertSame(18, Carbon::createFromDate(2012, 1, 31)->addWeekdays(-9)->day);
  94. }
  95. public function testAddWeekday()
  96. {
  97. $this->assertSame(9, Carbon::createFromDate(2012, 1, 6)->addWeekday()->day);
  98. }
  99. public function testAddWeeksPositive()
  100. {
  101. $this->assertSame(28, Carbon::createFromDate(1975, 5, 21)->addWeeks(1)->day);
  102. }
  103. public function testAddWeeksZero()
  104. {
  105. $this->assertSame(21, Carbon::createFromDate(1975, 5, 21)->addWeeks(0)->day);
  106. }
  107. public function testAddWeeksNegative()
  108. {
  109. $this->assertSame(14, Carbon::createFromDate(1975, 5, 21)->addWeeks(-1)->day);
  110. }
  111. public function testAddWeek()
  112. {
  113. $this->assertSame(28, Carbon::createFromDate(1975, 5, 21)->addWeek()->day);
  114. }
  115. public function testAddHoursPositive()
  116. {
  117. $this->assertSame(1, Carbon::createFromTime(0)->addHours(1)->hour);
  118. }
  119. public function testAddHoursZero()
  120. {
  121. $this->assertSame(0, Carbon::createFromTime(0)->addHours(0)->hour);
  122. }
  123. public function testAddHoursNegative()
  124. {
  125. $this->assertSame(23, Carbon::createFromTime(0)->addHours(-1)->hour);
  126. }
  127. public function testAddHour()
  128. {
  129. $this->assertSame(1, Carbon::createFromTime(0)->addHour()->hour);
  130. }
  131. public function testAddMinutesPositive()
  132. {
  133. $this->assertSame(1, Carbon::createFromTime(0, 0)->addMinutes(1)->minute);
  134. }
  135. public function testAddMinutesZero()
  136. {
  137. $this->assertSame(0, Carbon::createFromTime(0, 0)->addMinutes(0)->minute);
  138. }
  139. public function testAddMinutesNegative()
  140. {
  141. $this->assertSame(59, Carbon::createFromTime(0, 0)->addMinutes(-1)->minute);
  142. }
  143. public function testAddMinute()
  144. {
  145. $this->assertSame(1, Carbon::createFromTime(0, 0)->addMinute()->minute);
  146. }
  147. public function testAddSecondsPositive()
  148. {
  149. $this->assertSame(1, Carbon::createFromTime(0, 0, 0)->addSeconds(1)->second);
  150. }
  151. public function testAddSecondsZero()
  152. {
  153. $this->assertSame(0, Carbon::createFromTime(0, 0, 0)->addSeconds(0)->second);
  154. }
  155. public function testAddSecondsNegative()
  156. {
  157. $this->assertSame(59, Carbon::createFromTime(0, 0, 0)->addSeconds(-1)->second);
  158. }
  159. public function testAddSecond()
  160. {
  161. $this->assertSame(1, Carbon::createFromTime(0, 0, 0)->addSecond()->second);
  162. }
  163. }