Nessuna descrizione

DayOfWeekModifiersTest.php 8.5KB

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