DayOfWeekModifiersTest.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 DayOfWeekModifiersTest extends TestFixture
  12. {
  13. public function testStartOfWeek()
  14. {
  15. $d = Carbon::create(1980, 8, 7, 12, 11, 9)->startOfWeek();
  16. $this->assertCarbon($d, 1980, 8, 4, 0, 0, 0);
  17. }
  18. public function testStartOfWeekFromWeekStart()
  19. {
  20. $d = Carbon::createFromDate(1980, 8, 4)->startOfWeek();
  21. $this->assertCarbon($d, 1980, 8, 4, 0, 0, 0);
  22. }
  23. public function testEndOfWeek()
  24. {
  25. $d = Carbon::create(1980, 8, 7, 11, 12, 13)->endOfWeek();
  26. $this->assertCarbon($d, 1980, 8, 10, 23, 59, 59);
  27. }
  28. public function testEndOfWeekFromWeekEnd()
  29. {
  30. $d = Carbon::createFromDate(1980, 8, 9)->endOfWeek();
  31. $this->assertCarbon($d, 1980, 8, 10, 23, 59, 59);
  32. }
  33. public function testNext()
  34. {
  35. $d = Carbon::createFromDate(1975, 5, 21)->next();
  36. $this->assertCarbon($d, 1975, 5, 28, 0, 0, 0);
  37. }
  38. public function testNextMonday()
  39. {
  40. $d = Carbon::createFromDate(1975, 5, 21)->next(Carbon::MONDAY);
  41. $this->assertCarbon($d, 1975, 5, 26, 0, 0, 0);
  42. }
  43. public function testNextSaturday()
  44. {
  45. $d = Carbon::createFromDate(1975, 5, 21)->next(6);
  46. $this->assertCarbon($d, 1975, 5, 24, 0, 0, 0);
  47. }
  48. public function testNextTimestamp()
  49. {
  50. $d = Carbon::createFromDate(1975, 11, 14)->next();
  51. $this->assertCarbon($d, 1975, 11, 21, 0, 0, 0);
  52. }
  53. public function testPrevious()
  54. {
  55. $d = Carbon::createFromDate(1975, 5, 21)->previous();
  56. $this->assertCarbon($d, 1975, 5, 14, 0, 0, 0);
  57. }
  58. public function testPreviousMonday()
  59. {
  60. $d = Carbon::createFromDate(1975, 5, 21)->previous(Carbon::MONDAY);
  61. $this->assertCarbon($d, 1975, 5, 19, 0, 0, 0);
  62. }
  63. public function testPreviousSaturday()
  64. {
  65. $d = Carbon::createFromDate(1975, 5, 21)->previous(6);
  66. $this->assertCarbon($d, 1975, 5, 17, 0, 0, 0);
  67. }
  68. public function testPreviousTimestamp()
  69. {
  70. $d = Carbon::createFromDate(1975, 11, 28)->previous();
  71. $this->assertCarbon($d, 1975, 11, 21, 0, 0, 0);
  72. }
  73. public function testFirstDayOfMonth()
  74. {
  75. $d = Carbon::createFromDate(1975, 11, 21)->firstOfMonth();
  76. $this->assertCarbon($d, 1975, 11, 1, 0, 0, 0);
  77. }
  78. public function testFirstWednesdayOfMonth()
  79. {
  80. $d = Carbon::createFromDate(1975, 11, 21)->firstOfMonth(Carbon::WEDNESDAY);
  81. $this->assertCarbon($d, 1975, 11, 5, 0, 0, 0);
  82. }
  83. public function testFirstFridayOfMonth()
  84. {
  85. $d = Carbon::createFromDate(1975, 11, 21)->firstOfMonth(5);
  86. $this->assertCarbon($d, 1975, 11, 7, 0, 0, 0);
  87. }
  88. public function testLastDayOfMonth()
  89. {
  90. $d = Carbon::createFromDate(1975, 12, 5)->lastOfMonth();
  91. $this->assertCarbon($d, 1975, 12, 31, 0, 0, 0);
  92. }
  93. public function testLastTuesdayOfMonth()
  94. {
  95. $d = Carbon::createFromDate(1975, 12, 1)->lastOfMonth(Carbon::TUESDAY);
  96. $this->assertCarbon($d, 1975, 12, 30, 0, 0, 0);
  97. }
  98. public function testLastFridayOfMonth()
  99. {
  100. $d = Carbon::createFromDate(1975, 12, 5)->lastOfMonth(5);
  101. $this->assertCarbon($d, 1975, 12, 26, 0, 0, 0);
  102. }
  103. public function testNthOfMonthOutsideScope()
  104. {
  105. $this->assertFalse(Carbon::createFromDate(1975, 12, 5)->nthOfMonth(6, Carbon::MONDAY));
  106. }
  107. public function testNthOfMonthOutsideYear()
  108. {
  109. $this->assertFalse(Carbon::createFromDate(1975, 12, 5)->nthOfMonth(55, Carbon::MONDAY));
  110. }
  111. public function test2ndMondayOfMonth()
  112. {
  113. $d = Carbon::createFromDate(1975, 12, 5)->nthOfMonth(2, Carbon::MONDAY);
  114. $this->assertCarbon($d, 1975, 12, 8, 0, 0, 0);
  115. }
  116. public function test3rdWednesdayOfMonth()
  117. {
  118. $d = Carbon::createFromDate(1975, 12, 5)->nthOfMonth(3, 3);
  119. $this->assertCarbon($d, 1975, 12, 17, 0, 0, 0);
  120. }
  121. public function testFirstDayOfQuarter()
  122. {
  123. $d = Carbon::createFromDate(1975, 11, 21)->firstOfQuarter();
  124. $this->assertCarbon($d, 1975, 10, 1, 0, 0, 0);
  125. }
  126. public function testFirstWednesdayOfQuarter()
  127. {
  128. $d = Carbon::createFromDate(1975, 11, 21)->firstOfQuarter(Carbon::WEDNESDAY);
  129. $this->assertCarbon($d, 1975, 10, 1, 0, 0, 0);
  130. }
  131. public function testFirstFridayOfQuarter()
  132. {
  133. $d = Carbon::createFromDate(1975, 11, 21)->firstOfQuarter(5);
  134. $this->assertCarbon($d, 1975, 10, 3, 0, 0, 0);
  135. }
  136. public function testLastDayOfQuarter()
  137. {
  138. $d = Carbon::createFromDate(1975, 8, 5)->lastOfQuarter();
  139. $this->assertCarbon($d, 1975, 9, 30, 0, 0, 0);
  140. }
  141. public function testLastTuesdayOfQuarter()
  142. {
  143. $d = Carbon::createFromDate(1975, 8, 1)->lastOfQuarter(Carbon::TUESDAY);
  144. $this->assertCarbon($d, 1975, 9, 30, 0, 0, 0);
  145. }
  146. public function testLastFridayOfQuarter()
  147. {
  148. $d = Carbon::createFromDate(1975, 7, 5)->lastOfQuarter(5);
  149. $this->assertCarbon($d, 1975, 9, 26, 0, 0, 0);
  150. }
  151. public function testNthOfQuarterOutsideScope()
  152. {
  153. $this->assertFalse(Carbon::createFromDate(1975, 1, 5)->nthOfQuarter(20, Carbon::MONDAY));
  154. }
  155. public function testNthOfQuarterOutsideYear()
  156. {
  157. $this->assertFalse(Carbon::createFromDate(1975, 1, 5)->nthOfQuarter(55, Carbon::MONDAY));
  158. }
  159. public function test2ndMondayOfQuarter()
  160. {
  161. $d = Carbon::createFromDate(1975, 8, 5)->nthOfQuarter(2, Carbon::MONDAY);
  162. $this->assertCarbon($d, 1975, 7, 14, 0, 0, 0);
  163. }
  164. public function test3rdWednesdayOfQuarter()
  165. {
  166. $d = Carbon::createFromDate(1975, 8, 5)->nthOfQuarter(3, 3);
  167. $this->assertCarbon($d, 1975, 7, 16, 0, 0, 0);
  168. }
  169. public function testFirstDayOfYear()
  170. {
  171. $d = Carbon::createFromDate(1975, 11, 21)->firstOfYear();
  172. $this->assertCarbon($d, 1975, 1, 1, 0, 0, 0);
  173. }
  174. public function testFirstWednesdayOfYear()
  175. {
  176. $d = Carbon::createFromDate(1975, 11, 21)->firstOfYear(Carbon::WEDNESDAY);
  177. $this->assertCarbon($d, 1975, 1, 1, 0, 0, 0);
  178. }
  179. public function testFirstFridayOfYear()
  180. {
  181. $d = Carbon::createFromDate(1975, 11, 21)->firstOfYear(5);
  182. $this->assertCarbon($d, 1975, 1, 3, 0, 0, 0);
  183. }
  184. public function testLastDayOfYear()
  185. {
  186. $d = Carbon::createFromDate(1975, 8, 5)->lastOfYear();
  187. $this->assertCarbon($d, 1975, 12, 31, 0, 0, 0);
  188. }
  189. public function testLastTuesdayOfYear()
  190. {
  191. $d = Carbon::createFromDate(1975, 8, 1)->lastOfYear(Carbon::TUESDAY);
  192. $this->assertCarbon($d, 1975, 12, 30, 0, 0, 0);
  193. }
  194. public function testLastFridayOfYear()
  195. {
  196. $d = Carbon::createFromDate(1975, 7, 5)->lastOfYear(5);
  197. $this->assertCarbon($d, 1975, 12, 26, 0, 0, 0);
  198. }
  199. public function testNthOfYearOutsideScope()
  200. {
  201. $this->assertFalse(Carbon::createFromDate(1975, 1, 5)->nthOfYear(55, Carbon::MONDAY));
  202. }
  203. public function test2ndMondayOfYear()
  204. {
  205. $d = Carbon::createFromDate(1975, 8, 5)->nthOfYear(2, Carbon::MONDAY);
  206. $this->assertCarbon($d, 1975, 1, 13, 0, 0, 0);
  207. }
  208. public function test3rdWednesdayOfYear()
  209. {
  210. $d = Carbon::createFromDate(1975, 8, 5)->nthOfYear(3, 3);
  211. $this->assertCarbon($d, 1975, 1, 15, 0, 0, 0);
  212. }
  213. }