IsTest.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of the Carbon package.
  5. *
  6. * (c) Brian Nesbitt <brian@nesbot.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Tests\CarbonImmutable;
  12. use Carbon\CarbonImmutable as Carbon;
  13. use DateTime;
  14. use Generator;
  15. use InvalidArgumentException;
  16. use stdClass;
  17. use Tests\AbstractTestCase;
  18. class IsTest extends AbstractTestCase
  19. {
  20. public function testIsWeekdayTrue()
  21. {
  22. $this->assertTrue(Carbon::createFromDate(2012, 1, 2)->isWeekday());
  23. }
  24. public function testIsWeekdayFalse()
  25. {
  26. $this->assertFalse(Carbon::createFromDate(2012, 1, 1)->isWeekday());
  27. }
  28. public function testIsWeekendTrue()
  29. {
  30. $this->assertTrue(Carbon::createFromDate(2012, 1, 1)->isWeekend());
  31. }
  32. public function testIsWeekendFalse()
  33. {
  34. $this->assertFalse(Carbon::createFromDate(2012, 1, 2)->isWeekend());
  35. }
  36. public function testIsYesterdayTrue()
  37. {
  38. $this->assertTrue(Carbon::now()->subDay()->isYesterday());
  39. }
  40. public function testIsYesterdayFalseWithToday()
  41. {
  42. $this->assertFalse(Carbon::now()->endOfDay()->isYesterday());
  43. }
  44. public function testIsYesterdayFalseWith2Days()
  45. {
  46. $this->assertFalse(Carbon::now()->subDays(2)->startOfDay()->isYesterday());
  47. }
  48. public function testIsTodayTrue()
  49. {
  50. $this->assertTrue(Carbon::now()->isToday());
  51. }
  52. public function testIsCurrentWeek()
  53. {
  54. $this->assertFalse(Carbon::now()->subWeek()->isCurrentWeek());
  55. $this->assertFalse(Carbon::now()->addWeek()->isCurrentWeek());
  56. $this->assertTrue(Carbon::now()->isCurrentWeek());
  57. $this->assertTrue(Carbon::now()->startOfWeek()->isCurrentWeek());
  58. $this->assertTrue(Carbon::now()->endOfWeek()->isCurrentWeek());
  59. }
  60. public function testIsSameWeek()
  61. {
  62. $this->assertFalse(Carbon::now()->subWeek()->isSameWeek(Carbon::now()));
  63. $this->assertFalse(Carbon::now()->addWeek()->isSameWeek(Carbon::now()));
  64. $this->assertTrue(Carbon::now()->isSameWeek(Carbon::now()));
  65. $this->assertTrue(Carbon::now()->startOfWeek()->isSameWeek(Carbon::now()));
  66. $this->assertTrue(Carbon::now()->endOfWeek()->isSameWeek(Carbon::now()));
  67. $this->assertTrue(Carbon::parse('2019-01-01')->isSameWeek(Carbon::parse('2018-12-31')));
  68. }
  69. public function testIsNextWeekTrue()
  70. {
  71. $this->assertTrue(Carbon::now()->addWeek()->isNextWeek());
  72. }
  73. public function testIsLastWeekTrue()
  74. {
  75. $this->assertTrue(Carbon::now()->subWeek()->isLastWeek());
  76. }
  77. public function testIsNextWeekFalse()
  78. {
  79. /** @var mixed $date */
  80. $date = Carbon::now();
  81. $this->assertFalse($date->addWeek(2)->isNextWeek());
  82. }
  83. public function testIsLastWeekFalse()
  84. {
  85. /** @var mixed $date */
  86. $date = Carbon::now();
  87. $this->assertFalse($date->subWeek(2)->isLastWeek());
  88. }
  89. public function testIsNextQuarterTrue()
  90. {
  91. $this->assertTrue(Carbon::now()->addQuarterNoOverflow()->isNextQuarter());
  92. }
  93. public function testIsLastQuarterTrue()
  94. {
  95. $this->assertTrue(Carbon::now()->subQuarterNoOverflow()->isLastQuarter());
  96. }
  97. public function testIsNextQuarterFalse()
  98. {
  99. $this->assertFalse(Carbon::now()->addQuartersNoOverflow(2)->isNextQuarter());
  100. }
  101. public function testIsLastQuarterFalse()
  102. {
  103. $this->assertFalse(Carbon::now()->subQuartersNoOverflow(2)->isLastQuarter());
  104. }
  105. public function testIsNextMonthTrue()
  106. {
  107. $this->assertTrue(Carbon::now()->addMonthNoOverflow()->isNextMonth());
  108. }
  109. public function testIsLastMonthTrue()
  110. {
  111. $this->assertTrue(Carbon::now()->subMonthNoOverflow()->isLastMonth());
  112. }
  113. public function testIsNextMonthFalse()
  114. {
  115. $this->assertFalse(Carbon::now()->addMonthsNoOverflow(2)->isNextMonth());
  116. }
  117. public function testIsLastMonthFalse()
  118. {
  119. $this->assertFalse(Carbon::now()->subMonthsNoOverflow(2)->isLastMonth());
  120. }
  121. public function testIsNextYearTrue()
  122. {
  123. $this->assertTrue(Carbon::now()->addYear()->isNextYear());
  124. }
  125. public function testIsLastYearTrue()
  126. {
  127. $this->assertTrue(Carbon::now()->subYear()->isLastYear());
  128. }
  129. public function testIsNextYearFalse()
  130. {
  131. /** @var mixed $date */
  132. $date = Carbon::now();
  133. $this->assertFalse($date->addYear(2)->isNextYear());
  134. }
  135. public function testIsLastYearFalse()
  136. {
  137. /** @var mixed $date */
  138. $date = Carbon::now();
  139. $this->assertFalse($date->subYear(2)->isLastYear());
  140. }
  141. public function testIsTodayFalseWithYesterday()
  142. {
  143. $this->assertFalse(Carbon::now()->subDay()->endOfDay()->isToday());
  144. }
  145. public function testIsTodayFalseWithTomorrow()
  146. {
  147. $this->assertFalse(Carbon::now()->addDay()->startOfDay()->isToday());
  148. }
  149. public function testIsTodayWithTimezone()
  150. {
  151. $this->assertTrue(Carbon::now('Asia/Tokyo')->isToday());
  152. }
  153. public function testIsTomorrowTrue()
  154. {
  155. $this->assertTrue(Carbon::now()->addDay()->isTomorrow());
  156. }
  157. public function testIsTomorrowFalseWithToday()
  158. {
  159. $this->assertFalse(Carbon::now()->endOfDay()->isTomorrow());
  160. }
  161. public function testIsTomorrowFalseWith2Days()
  162. {
  163. $this->assertFalse(Carbon::now()->addDays(2)->startOfDay()->isTomorrow());
  164. }
  165. public function testIsFutureTrue()
  166. {
  167. $this->assertTrue(Carbon::now()->addSecond()->isFuture());
  168. }
  169. public function testIsFutureFalse()
  170. {
  171. $this->assertFalse(Carbon::now()->isFuture());
  172. }
  173. public function testIsFutureFalseInThePast()
  174. {
  175. $this->assertFalse(Carbon::now()->subSecond()->isFuture());
  176. }
  177. public function testIsPastTrue()
  178. {
  179. $this->assertTrue(Carbon::now()->subSecond()->isPast());
  180. }
  181. public function testIsPastFalse()
  182. {
  183. $this->assertFalse(Carbon::now()->addSecond()->isPast());
  184. }
  185. public function testNowIsPastFalse()
  186. {
  187. $this->assertFalse(Carbon::now()->isPast());
  188. }
  189. public function testIsLeapYearTrue()
  190. {
  191. $this->assertTrue(Carbon::createFromDate(2016, 1, 1)->isLeapYear());
  192. }
  193. public function testIsLeapYearFalse()
  194. {
  195. $this->assertFalse(Carbon::createFromDate(2014, 1, 1)->isLeapYear());
  196. }
  197. public function testIsCurrentYearTrue()
  198. {
  199. $this->assertTrue(Carbon::now()->isCurrentYear());
  200. }
  201. public function testIsCurrentYearFalse()
  202. {
  203. $this->assertFalse(Carbon::now()->subYear()->isCurrentYear());
  204. }
  205. public function testIsSameYearTrue()
  206. {
  207. $this->assertTrue(Carbon::now()->isSameYear(Carbon::now()));
  208. }
  209. public function testIsSameYearFalse()
  210. {
  211. $this->assertFalse(Carbon::now()->isSameYear(Carbon::now()->subYear()));
  212. }
  213. public function testIsCurrentDecadeTrue()
  214. {
  215. $this->assertTrue(Carbon::now()->isCurrentDecade());
  216. }
  217. public function testIsCurrentDecadeFalse()
  218. {
  219. $this->assertFalse(Carbon::now()->subDecade()->isCurrentDecade());
  220. }
  221. public function testIsSameDecadeTrue()
  222. {
  223. $this->assertTrue(Carbon::now()->isSameDecade(Carbon::now()));
  224. $this->assertTrue(Carbon::now()->isSameUnit('millennium', Carbon::now()));
  225. }
  226. public function testIsSameDecadeFalse()
  227. {
  228. $this->assertFalse(Carbon::now()->isSameDecade(Carbon::now()->subDecade()));
  229. $this->assertFalse(Carbon::now()->isSameUnit('millennium', Carbon::now()->subMillennia(2)));
  230. }
  231. public function testIsSameFoobar()
  232. {
  233. $this->expectExceptionObject(new InvalidArgumentException(
  234. 'Bad comparison unit: \'foobar\''
  235. ));
  236. Carbon::now()->isSameUnit('foobar', Carbon::now()->subMillennium());
  237. }
  238. public function testIsCurrentQuarterTrue()
  239. {
  240. $this->assertTrue(Carbon::now()->isCurrentQuarter());
  241. }
  242. public function testIsCurrentQuarterFalse()
  243. {
  244. Carbon::useMonthsOverflow(false);
  245. $this->assertFalse(Carbon::now()->subQuarter()->isCurrentQuarter());
  246. Carbon::resetMonthsOverflow();
  247. }
  248. public function testIsSameQuarterTrue()
  249. {
  250. $this->assertTrue(Carbon::now()->isSameQuarter(Carbon::now()));
  251. }
  252. public function testIsSameQuarterTrueWithDateTime()
  253. {
  254. $this->assertTrue(Carbon::now()->isSameQuarter(new DateTime()));
  255. }
  256. public function testIsSameQuarterFalse()
  257. {
  258. Carbon::useMonthsOverflow(false);
  259. $this->assertFalse(Carbon::now()->isSameQuarter(Carbon::now()->subQuarter()));
  260. Carbon::resetMonthsOverflow();
  261. }
  262. public function testIsSameQuarterFalseWithDateTime()
  263. {
  264. $now = Carbon::now();
  265. $dt = new DateTime();
  266. $dt->modify((Carbon::MONTHS_PER_QUARTER * -1).' month');
  267. if ($dt->format('d') !== $now->format('d')) {
  268. $dt->modify('last day of previous month');
  269. }
  270. $this->assertFalse($now->isSameQuarter($dt));
  271. }
  272. public function testIsSameQuarterAndYearTrue()
  273. {
  274. $this->assertTrue(Carbon::now()->isSameQuarter(Carbon::now(), true));
  275. }
  276. public function testIsSameQuarterAndYearTrueWithDateTime()
  277. {
  278. $this->assertTrue(Carbon::now()->isSameQuarter(new DateTime(), true));
  279. }
  280. public function testIsSameQuarterAndYearFalse()
  281. {
  282. $this->assertFalse(Carbon::now()->isSameQuarter(Carbon::now()->subYear(), true));
  283. }
  284. public function testIsSameQuarterAndYearFalseWithDateTime()
  285. {
  286. $dt = new DateTime();
  287. $dt->modify('-1 year');
  288. $this->assertFalse(Carbon::now()->isSameQuarter($dt, true));
  289. }
  290. public function testIsCurrentMonth()
  291. {
  292. $this->assertTrue(Carbon::now()->isCurrentMonth());
  293. $dt = Carbon::now();
  294. $dt = $dt->modify(Carbon::now()->year.$dt->format('-m-').'01');
  295. $this->assertTrue($dt->isCurrentMonth());
  296. $dt = $dt->modify((Carbon::now()->year + 1).$dt->format('-m-').'28');
  297. $this->assertFalse($dt->isCurrentMonth());
  298. }
  299. public function testIsCurrentMonthFalse()
  300. {
  301. $this->assertFalse(Carbon::now()->day(15)->subMonth()->isCurrentMonth());
  302. $this->assertFalse(Carbon::now()->day(15)->addYear()->isCurrentMonth());
  303. }
  304. public function testIsSameMonth()
  305. {
  306. $this->assertTrue(Carbon::now()->isSameMonth(Carbon::now()));
  307. $dt = Carbon::now();
  308. for ($year = 1990; $year < Carbon::now()->year; $year++) {
  309. $dt->modify($year.$dt->format('-m-').'01');
  310. $this->assertTrue(Carbon::now()->isSameMonth($dt, false));
  311. $dt->modify($year.$dt->format('-m-').'28');
  312. $this->assertTrue(Carbon::now()->isSameMonth($dt, false));
  313. }
  314. }
  315. public function testIsSameMonthTrueWithDateTime()
  316. {
  317. $this->assertTrue(Carbon::now()->isSameMonth(new DateTime()));
  318. $dt = new DateTime();
  319. for ($year = 1990; $year < 2200; $year++) {
  320. $dt->modify($year.$dt->format('-m-').'01');
  321. $this->assertTrue(Carbon::now()->isSameMonth($dt, false));
  322. $dt->modify($year.$dt->format('-m-').'28');
  323. $this->assertTrue(Carbon::now()->isSameMonth($dt, false));
  324. }
  325. }
  326. public function testIsSameMonthOfSameYear()
  327. {
  328. $this->assertFalse(Carbon::now()->isSameMonth(Carbon::now()->day(15)->subMonth()));
  329. $this->assertTrue(Carbon::now()->isSameMonth(Carbon::now()));
  330. $dt = Carbon::now();
  331. for ($year = 1990; $year < Carbon::now()->year; $year++) {
  332. $dt = $dt->modify($year.$dt->format('-m-').'01');
  333. $this->assertFalse(Carbon::now()->isSameMonth($dt, true));
  334. $dt = $dt->modify($year.$dt->format('-m-').'28');
  335. $this->assertFalse(Carbon::now()->isSameMonth($dt, true));
  336. }
  337. $year = Carbon::now()->year;
  338. $dt = $dt->modify($year.$dt->format('-m-').'01');
  339. $this->assertTrue(Carbon::now()->isSameMonth($dt, true));
  340. $dt = $dt->modify($year.$dt->format('-m-').'28');
  341. $this->assertTrue(Carbon::now()->isSameMonth($dt, true));
  342. for ($year = Carbon::now()->year + 1; $year < 2200; $year++) {
  343. $dt = $dt->modify($year.$dt->format('-m-').'01');
  344. $this->assertFalse(Carbon::now()->isSameMonth($dt, true));
  345. $dt = $dt->modify($year.$dt->format('-m-').'28');
  346. $this->assertFalse(Carbon::now()->isSameMonth($dt, true));
  347. }
  348. }
  349. public function testIsSameMonthFalseWithDateTime()
  350. {
  351. $dt = new DateTime();
  352. $dt = $dt->modify('-2 month');
  353. $this->assertFalse(Carbon::now()->isSameMonth($dt));
  354. }
  355. public function testIsSameMonthAndYearTrue()
  356. {
  357. $this->assertTrue(Carbon::now()->isSameMonth(Carbon::now(), true));
  358. $dt = Carbon::now();
  359. $dt = $dt->modify($dt->format('Y-m-').'01');
  360. $this->assertTrue(Carbon::now()->isSameMonth($dt, true));
  361. $dt = $dt->modify($dt->format('Y-m-').'28');
  362. $this->assertTrue(Carbon::now()->isSameMonth($dt, true));
  363. }
  364. public function testIsSameMonthAndYearTrueWithDateTime()
  365. {
  366. $this->assertTrue(Carbon::now()->isSameMonth(new DateTime(), true));
  367. $dt = new DateTime();
  368. $dt = $dt->modify($dt->format('Y-m-').'01');
  369. $this->assertTrue(Carbon::now()->isSameMonth($dt, true));
  370. $dt = $dt->modify($dt->format('Y-m-').'28');
  371. $this->assertTrue(Carbon::now()->isSameMonth($dt, true));
  372. }
  373. public function testIsSameMonthAndYearFalse()
  374. {
  375. $this->assertFalse(Carbon::now()->isSameMonth(Carbon::now()->subYear(), true));
  376. }
  377. public function testIsSameMonthAndYearFalseWithDateTime()
  378. {
  379. $dt = new DateTime();
  380. $dt = $dt->modify('-1 year');
  381. $this->assertFalse(Carbon::now()->isSameMonth($dt, true));
  382. }
  383. public function testIsSameDayTrue()
  384. {
  385. $current = Carbon::createFromDate(2012, 1, 2);
  386. $this->assertTrue($current->isSameDay(Carbon::createFromDate(2012, 1, 2)));
  387. $this->assertTrue($current->isSameDay(Carbon::create(2012, 1, 2, 23, 59, 59)));
  388. }
  389. public function testIsSameDayWithString()
  390. {
  391. $current = Carbon::createFromDate(2012, 1, 2);
  392. $this->assertTrue($current->isSameDay('2012-01-02 15:00:25'));
  393. $this->assertTrue($current->isSameDay('2012-01-02'));
  394. }
  395. public function testIsSameDayTrueWithDateTime()
  396. {
  397. $current = Carbon::createFromDate(2012, 1, 2);
  398. $this->assertTrue($current->isSameDay(new DateTime('2012-01-02')));
  399. $this->assertTrue($current->isSameDay(new DateTime('2012-01-02 23:59:59')));
  400. }
  401. public function testIsSameDayFalse()
  402. {
  403. $current = Carbon::createFromDate(2012, 1, 2);
  404. $this->assertFalse($current->isSameDay(Carbon::createFromDate(2012, 1, 3)));
  405. $this->assertFalse($current->isSameDay(Carbon::createFromDate(2012, 6, 2)));
  406. }
  407. public function testIsSameDayFalseWithDateTime()
  408. {
  409. $current = Carbon::createFromDate(2012, 1, 2);
  410. $this->assertFalse($current->isSameDay(new DateTime('2012-01-03')));
  411. $this->assertFalse($current->isSameDay(new DateTime('2012-05-02')));
  412. }
  413. public function testIsCurrentDayTrue()
  414. {
  415. $this->assertTrue(Carbon::now()->isCurrentDay());
  416. $this->assertTrue(Carbon::now()->hour(0)->isCurrentDay());
  417. $this->assertTrue(Carbon::now()->hour(23)->isCurrentDay());
  418. }
  419. public function testIsCurrentDayFalse()
  420. {
  421. $this->assertFalse(Carbon::now()->subDay()->isCurrentDay());
  422. $this->assertFalse(Carbon::now()->subMonth()->isCurrentDay());
  423. }
  424. public function testIsSameHourTrue()
  425. {
  426. $current = Carbon::create(2018, 5, 6, 12);
  427. $this->assertTrue($current->isSameHour(Carbon::create(2018, 5, 6, 12)));
  428. $this->assertTrue($current->isSameHour(Carbon::create(2018, 5, 6, 12, 59, 59)));
  429. }
  430. public function testIsSameHourTrueWithDateTime()
  431. {
  432. $current = Carbon::create(2018, 5, 6, 12);
  433. $this->assertTrue($current->isSameHour(new DateTime('2018-05-06T12:00:00')));
  434. $this->assertTrue($current->isSameHour(new DateTime('2018-05-06T12:59:59')));
  435. }
  436. public function testIsSameHourFalse()
  437. {
  438. $current = Carbon::create(2018, 5, 6, 12);
  439. $this->assertFalse($current->isSameHour(Carbon::create(2018, 5, 6, 13)));
  440. $this->assertFalse($current->isSameHour(Carbon::create(2018, 5, 5, 12)));
  441. }
  442. public function testIsSameHourFalseWithDateTime()
  443. {
  444. $current = Carbon::create(2018, 5, 6, 12);
  445. $this->assertFalse($current->isSameHour(new DateTime('2018-05-06T13:00:00')));
  446. $this->assertFalse($current->isSameHour(new DateTime('2018-06-06T12:00:00')));
  447. }
  448. public function testIsCurrentHourTrue()
  449. {
  450. $this->assertTrue(Carbon::now()->isCurrentHour());
  451. $this->assertTrue(Carbon::now()->second(1)->isCurrentHour());
  452. $this->assertTrue(Carbon::now()->second(12)->isCurrentHour());
  453. $this->assertTrue(Carbon::now()->minute(0)->isCurrentHour());
  454. $this->assertTrue(Carbon::now()->minute(59)->second(59)->isCurrentHour());
  455. }
  456. public function testIsCurrentHourFalse()
  457. {
  458. $this->assertFalse(Carbon::now()->subHour()->isCurrentHour());
  459. $this->assertFalse(Carbon::now()->subDay()->isCurrentHour());
  460. }
  461. public function testIsSameMinuteTrue()
  462. {
  463. $current = Carbon::create(2018, 5, 6, 12, 30);
  464. $this->assertTrue($current->isSameMinute(Carbon::create(2018, 5, 6, 12, 30)));
  465. $current = Carbon::create(2018, 5, 6, 12, 30, 15);
  466. $this->assertTrue($current->isSameMinute(Carbon::create(2018, 5, 6, 12, 30, 45)));
  467. }
  468. public function testIsSameMinuteTrueWithDateTime()
  469. {
  470. $current = Carbon::create(2018, 5, 6, 12, 30);
  471. $this->assertTrue($current->isSameMinute(new DateTime('2018-05-06T12:30:00')));
  472. $current = Carbon::create(2018, 5, 6, 12, 30, 20);
  473. $this->assertTrue($current->isSameMinute(new DateTime('2018-05-06T12:30:40')));
  474. }
  475. public function testIsSameMinuteFalse()
  476. {
  477. $current = Carbon::create(2018, 5, 6, 12, 30);
  478. $this->assertFalse($current->isSameMinute(Carbon::create(2018, 5, 6, 13, 31)));
  479. $this->assertFalse($current->isSameMinute(Carbon::create(2019, 5, 6, 13, 30)));
  480. }
  481. public function testIsSameMinuteFalseWithDateTime()
  482. {
  483. $current = Carbon::create(2018, 5, 6, 12, 30);
  484. $this->assertFalse($current->isSameMinute(new DateTime('2018-05-06T13:31:00')));
  485. $this->assertFalse($current->isSameMinute(new DateTime('2018-05-06T17:30:00')));
  486. }
  487. public function testIsCurrentMinuteTrue()
  488. {
  489. $this->assertTrue(Carbon::now()->isCurrentMinute());
  490. $this->assertTrue(Carbon::now()->second(0)->isCurrentMinute());
  491. $this->assertTrue(Carbon::now()->second(59)->isCurrentMinute());
  492. }
  493. public function testIsCurrentMinuteFalse()
  494. {
  495. $this->assertFalse(Carbon::now()->subMinute()->isCurrentMinute());
  496. $this->assertFalse(Carbon::now()->subHour()->isCurrentMinute());
  497. }
  498. public function testIsSameSecondTrue()
  499. {
  500. $current = Carbon::create(2018, 5, 6, 12, 30, 13);
  501. $other = Carbon::create(2018, 5, 6, 12, 30, 13);
  502. $this->assertTrue($current->isSameSecond($other));
  503. $this->assertTrue($current->modify($current->hour.':'.$current->minute.':'.$current->second.'.0')->isSameSecond($other));
  504. $this->assertTrue($current->modify($current->hour.':'.$current->minute.':'.$current->second.'.999999')->isSameSecond($other));
  505. }
  506. public function testIsSameSecondTrueWithDateTime()
  507. {
  508. $current = Carbon::create(2018, 5, 6, 12, 30, 13);
  509. $this->assertTrue($current->isSameSecond(new DateTime('2018-05-06T12:30:13')));
  510. }
  511. public function testIsSameSecondFalse()
  512. {
  513. $current = Carbon::create(2018, 5, 6, 12, 30, 13);
  514. $this->assertFalse($current->isSameSecond(Carbon::create(2018, 5, 6, 12, 30, 55)));
  515. $this->assertFalse($current->isSameSecond(Carbon::create(2018, 5, 6, 14, 30, 13)));
  516. }
  517. public function testIsSameSecondFalseWithDateTime()
  518. {
  519. $current = Carbon::create(2018, 5, 6, 12, 30, 13);
  520. $this->assertFalse($current->isSameSecond(new DateTime('2018-05-06T13:30:54')));
  521. $this->assertFalse($current->isSameSecond(new DateTime('2018-05-06T13:36:13')));
  522. }
  523. public function testIsCurrentSecondTrue()
  524. {
  525. $this->assertTrue(Carbon::now()->isCurrentSecond());
  526. $now = Carbon::now();
  527. $this->assertTrue($now->modify($now->hour.':'.$now->minute.':'.$now->second.'.0')->isCurrentSecond());
  528. $this->assertTrue($now->modify($now->hour.':'.$now->minute.':'.$now->second.'.999999')->isCurrentSecond());
  529. }
  530. public function testIsCurrentSecondFalse()
  531. {
  532. $this->assertFalse(Carbon::now()->subSecond()->isCurrentSecond());
  533. $this->assertFalse(Carbon::now()->subDay()->isCurrentSecond());
  534. }
  535. public function testIsDayOfWeek()
  536. {
  537. // True in the past past
  538. $this->assertTrue(Carbon::createFromDate(2015, 5, 31)->isDayOfWeek(0));
  539. $this->assertTrue(Carbon::createFromDate(2015, 6, 21)->isDayOfWeek(0));
  540. $this->assertTrue(Carbon::now()->subWeek()->previous(Carbon::SUNDAY)->isDayOfWeek(0));
  541. $this->assertTrue(Carbon::now()->subWeek()->previous(Carbon::SUNDAY)->isDayOfWeek('sunday'));
  542. $this->assertTrue(Carbon::now()->subWeek()->previous(Carbon::SUNDAY)->isDayOfWeek('SUNDAY'));
  543. // True in the future
  544. $this->assertTrue(Carbon::now()->addWeek()->previous(Carbon::SUNDAY)->isDayOfWeek(0));
  545. $this->assertTrue(Carbon::now()->addMonth()->previous(Carbon::SUNDAY)->isDayOfWeek(0));
  546. $this->assertTrue(Carbon::now()->addMonth()->previous(Carbon::SUNDAY)->isDayOfWeek('sunday'));
  547. $this->assertTrue(Carbon::now()->addMonth()->previous(Carbon::SUNDAY)->isDayOfWeek('SUNDAY'));
  548. $this->assertTrue(Carbon::now()->addMonth()->previous(Carbon::MONDAY)->isDayOfWeek('monday'));
  549. $this->assertTrue(Carbon::now()->addMonth()->previous(Carbon::MONDAY)->isDayOfWeek('MONDAY'));
  550. // False in the past
  551. $this->assertFalse(Carbon::now()->subWeek()->previous(Carbon::MONDAY)->isDayOfWeek(0));
  552. $this->assertFalse(Carbon::now()->subMonth()->previous(Carbon::MONDAY)->isDayOfWeek(0));
  553. $this->assertFalse(Carbon::now()->subMonth()->previous(Carbon::MONDAY)->isDayOfWeek('sunday'));
  554. $this->assertFalse(Carbon::now()->subMonth()->previous(Carbon::MONDAY)->isDayOfWeek('SUNDAY'));
  555. $this->assertFalse(Carbon::now()->subMonth()->previous(Carbon::SUNDAY)->isDayOfWeek('monday'));
  556. $this->assertFalse(Carbon::now()->subMonth()->previous(Carbon::SUNDAY)->isDayOfWeek('MONDAY'));
  557. // False in the future
  558. $this->assertFalse(Carbon::now()->addWeek()->previous(Carbon::MONDAY)->isDayOfWeek(0));
  559. $this->assertFalse(Carbon::now()->addMonth()->previous(Carbon::MONDAY)->isDayOfWeek(0));
  560. $this->assertFalse(Carbon::now()->addMonth()->previous(Carbon::MONDAY)->isDayOfWeek('sunday'));
  561. $this->assertFalse(Carbon::now()->addMonth()->previous(Carbon::MONDAY)->isDayOfWeek('SUNDAY'));
  562. $this->assertFalse(Carbon::now()->addMonth()->previous(Carbon::SUNDAY)->isDayOfWeek('monday'));
  563. $this->assertFalse(Carbon::now()->addMonth()->previous(Carbon::SUNDAY)->isDayOfWeek('MONDAY'));
  564. }
  565. public function testIsSameAs()
  566. {
  567. $current = Carbon::createFromDate(2012, 1, 2);
  568. $this->assertTrue($current->isSameAs('c', $current));
  569. }
  570. public function testIsSameAsWithInvalidArgument()
  571. {
  572. $this->expectExceptionObject(new InvalidArgumentException(
  573. 'Expected null, string, DateTime or DateTimeInterface, stdClass given'
  574. ));
  575. $current = Carbon::createFromDate(2012, 1, 2);
  576. $current->isSameAs('Y-m-d', new stdClass());
  577. }
  578. public function testIsSunday()
  579. {
  580. // True in the past past
  581. $this->assertTrue(Carbon::createFromDate(2015, 5, 31)->isSunday());
  582. $this->assertTrue(Carbon::createFromDate(2015, 6, 21)->isSunday());
  583. $this->assertTrue(Carbon::now()->subWeek()->previous(Carbon::SUNDAY)->isSunday());
  584. // True in the future
  585. $this->assertTrue(Carbon::now()->addWeek()->previous(Carbon::SUNDAY)->isSunday());
  586. $this->assertTrue(Carbon::now()->addMonth()->previous(Carbon::SUNDAY)->isSunday());
  587. // False in the past
  588. $this->assertFalse(Carbon::now()->subWeek()->previous(Carbon::MONDAY)->isSunday());
  589. $this->assertFalse(Carbon::now()->subMonth()->previous(Carbon::MONDAY)->isSunday());
  590. // False in the future
  591. $this->assertFalse(Carbon::now()->addWeek()->previous(Carbon::MONDAY)->isSunday());
  592. $this->assertFalse(Carbon::now()->addMonth()->previous(Carbon::MONDAY)->isSunday());
  593. }
  594. public function testIsMonday()
  595. {
  596. // True in the past past
  597. $this->assertTrue(Carbon::createFromDate(2015, 6, 1)->isMonday());
  598. $this->assertTrue(Carbon::now()->subWeek()->previous(Carbon::MONDAY)->isMonday());
  599. // True in the future
  600. $this->assertTrue(Carbon::now()->addWeek()->previous(Carbon::MONDAY)->isMonday());
  601. $this->assertTrue(Carbon::now()->addMonth()->previous(Carbon::MONDAY)->isMonday());
  602. // False in the past
  603. $this->assertFalse(Carbon::now()->subWeek()->previous(Carbon::TUESDAY)->isMonday());
  604. $this->assertFalse(Carbon::now()->subMonth()->previous(Carbon::TUESDAY)->isMonday());
  605. // False in the future
  606. $this->assertFalse(Carbon::now()->addWeek()->previous(Carbon::TUESDAY)->isMonday());
  607. $this->assertFalse(Carbon::now()->addMonth()->previous(Carbon::TUESDAY)->isMonday());
  608. }
  609. public function testIsTuesday()
  610. {
  611. // True in the past past
  612. $this->assertTrue(Carbon::createFromDate(2015, 6, 2)->isTuesday());
  613. $this->assertTrue(Carbon::now()->subWeek()->previous(Carbon::TUESDAY)->isTuesday());
  614. // True in the future
  615. $this->assertTrue(Carbon::now()->addWeek()->previous(Carbon::TUESDAY)->isTuesday());
  616. $this->assertTrue(Carbon::now()->addMonth()->previous(Carbon::TUESDAY)->isTuesday());
  617. // False in the past
  618. $this->assertFalse(Carbon::now()->subWeek()->previous(Carbon::WEDNESDAY)->isTuesday());
  619. $this->assertFalse(Carbon::now()->subMonth()->previous(Carbon::WEDNESDAY)->isTuesday());
  620. // False in the future
  621. $this->assertFalse(Carbon::now()->addWeek()->previous(Carbon::WEDNESDAY)->isTuesday());
  622. $this->assertFalse(Carbon::now()->addMonth()->previous(Carbon::WEDNESDAY)->isTuesday());
  623. }
  624. public function testIsWednesday()
  625. {
  626. // True in the past past
  627. $this->assertTrue(Carbon::createFromDate(2015, 6, 3)->isWednesday());
  628. $this->assertTrue(Carbon::now()->subWeek()->previous(Carbon::WEDNESDAY)->isWednesday());
  629. // True in the future
  630. $this->assertTrue(Carbon::now()->addWeek()->previous(Carbon::WEDNESDAY)->isWednesday());
  631. $this->assertTrue(Carbon::now()->addMonth()->previous(Carbon::WEDNESDAY)->isWednesday());
  632. // False in the past
  633. $this->assertFalse(Carbon::now()->subWeek()->previous(Carbon::THURSDAY)->isWednesday());
  634. $this->assertFalse(Carbon::now()->subMonth()->previous(Carbon::THURSDAY)->isWednesday());
  635. // False in the future
  636. $this->assertFalse(Carbon::now()->addWeek()->previous(Carbon::THURSDAY)->isWednesday());
  637. $this->assertFalse(Carbon::now()->addMonth()->previous(Carbon::THURSDAY)->isWednesday());
  638. }
  639. public function testIsThursday()
  640. {
  641. // True in the past past
  642. $this->assertTrue(Carbon::createFromDate(2015, 6, 4)->isThursday());
  643. $this->assertTrue(Carbon::now()->subWeek()->previous(Carbon::THURSDAY)->isThursday());
  644. // True in the future
  645. $this->assertTrue(Carbon::now()->addWeek()->previous(Carbon::THURSDAY)->isThursday());
  646. $this->assertTrue(Carbon::now()->addMonth()->previous(Carbon::THURSDAY)->isThursday());
  647. // False in the past
  648. $this->assertFalse(Carbon::now()->subWeek()->previous(Carbon::FRIDAY)->isThursday());
  649. $this->assertFalse(Carbon::now()->subMonth()->previous(Carbon::FRIDAY)->isThursday());
  650. // False in the future
  651. $this->assertFalse(Carbon::now()->addWeek()->previous(Carbon::FRIDAY)->isThursday());
  652. $this->assertFalse(Carbon::now()->addMonth()->previous(Carbon::FRIDAY)->isThursday());
  653. }
  654. public function testIsFriday()
  655. {
  656. // True in the past past
  657. $this->assertTrue(Carbon::createFromDate(2015, 6, 5)->isFriday());
  658. $this->assertTrue(Carbon::now()->subWeek()->previous(Carbon::FRIDAY)->isFriday());
  659. // True in the future
  660. $this->assertTrue(Carbon::now()->addWeek()->previous(Carbon::FRIDAY)->isFriday());
  661. $this->assertTrue(Carbon::now()->addMonth()->previous(Carbon::FRIDAY)->isFriday());
  662. // False in the past
  663. $this->assertFalse(Carbon::now()->subWeek()->previous(Carbon::SATURDAY)->isFriday());
  664. $this->assertFalse(Carbon::now()->subMonth()->previous(Carbon::SATURDAY)->isFriday());
  665. // False in the future
  666. $this->assertFalse(Carbon::now()->addWeek()->previous(Carbon::SATURDAY)->isFriday());
  667. $this->assertFalse(Carbon::now()->addMonth()->previous(Carbon::SATURDAY)->isFriday());
  668. }
  669. public function testIsSaturday()
  670. {
  671. // True in the past past
  672. $this->assertTrue(Carbon::createFromDate(2015, 6, 6)->isSaturday());
  673. $this->assertTrue(Carbon::now()->subWeek()->previous(Carbon::SATURDAY)->isSaturday());
  674. // True in the future
  675. $this->assertTrue(Carbon::now()->addWeek()->previous(Carbon::SATURDAY)->isSaturday());
  676. $this->assertTrue(Carbon::now()->addMonth()->previous(Carbon::SATURDAY)->isSaturday());
  677. // False in the past
  678. $this->assertFalse(Carbon::now()->subWeek()->previous(Carbon::SUNDAY)->isSaturday());
  679. $this->assertFalse(Carbon::now()->subMonth()->previous(Carbon::SUNDAY)->isSaturday());
  680. // False in the future
  681. $this->assertFalse(Carbon::now()->addWeek()->previous(Carbon::SUNDAY)->isSaturday());
  682. $this->assertFalse(Carbon::now()->addMonth()->previous(Carbon::SUNDAY)->isSaturday());
  683. }
  684. public function testIsStartOfDay()
  685. {
  686. $this->assertTrue(Carbon::parse('00:00:00')->isStartOfDay(false));
  687. $this->assertTrue(Carbon::parse('00:00:00.999999')->isStartOfDay(false));
  688. $this->assertTrue(Carbon::now()->startOfDay()->isStartOfDay(false));
  689. $this->assertFalse(Carbon::parse('15:30:45')->isStartOfDay(false));
  690. $this->assertFalse(Carbon::now()->endOfDay()->isStartOfDay(false));
  691. $this->assertTrue(Carbon::parse('00:00:00')->isStartOfDay());
  692. $this->assertTrue(Carbon::parse('00:00:00.999999')->isStartOfDay());
  693. $this->assertTrue(Carbon::now()->startOfDay()->isStartOfDay());
  694. $this->assertFalse(Carbon::parse('15:30:45')->isStartOfDay());
  695. $this->assertFalse(Carbon::now()->endOfDay()->isStartOfDay());
  696. }
  697. public function testIsStartOfDayWithMicroseconds()
  698. {
  699. $this->assertTrue(Carbon::parse('00:00:00')->isStartOfDay(true));
  700. $this->assertTrue(Carbon::now()->startOfDay()->isStartOfDay(true));
  701. $this->assertFalse(Carbon::parse('00:00:00.000001')->isStartOfDay(true));
  702. }
  703. public function testIsEndOfDay()
  704. {
  705. $this->assertTrue(Carbon::parse('23:59:59')->isEndOfDay(false));
  706. $this->assertTrue(Carbon::parse('23:59:59.000000')->isEndOfDay(false));
  707. $this->assertTrue(Carbon::now()->endOfDay()->isEndOfDay(false));
  708. $this->assertFalse(Carbon::parse('15:30:45')->isEndOfDay(false));
  709. $this->assertFalse(Carbon::now()->startOfDay()->isEndOfDay(false));
  710. $this->assertTrue(Carbon::parse('23:59:59')->isEndOfDay());
  711. $this->assertTrue(Carbon::parse('23:59:59.000000')->isEndOfDay());
  712. $this->assertTrue(Carbon::now()->endOfDay()->isEndOfDay());
  713. $this->assertFalse(Carbon::parse('15:30:45')->isEndOfDay());
  714. $this->assertFalse(Carbon::now()->startOfDay()->isEndOfDay());
  715. }
  716. public function testIsEndOfDayWithMicroseconds()
  717. {
  718. $this->assertTrue(Carbon::parse('23:59:59.999999')->isEndOfDay(true));
  719. $this->assertTrue(Carbon::now()->endOfDay()->isEndOfDay(true));
  720. $this->assertFalse(Carbon::parse('23:59:59')->isEndOfDay(true));
  721. $this->assertFalse(Carbon::parse('23:59:59.999998')->isEndOfDay(true));
  722. }
  723. public function testIsMidnight()
  724. {
  725. $this->assertTrue(Carbon::parse('00:00:00')->isMidnight());
  726. $this->assertFalse(Carbon::parse('15:30:45')->isMidnight());
  727. }
  728. public function testIsMidday()
  729. {
  730. $this->assertTrue(Carbon::parse('12:00:00')->isMidday());
  731. $this->assertFalse(Carbon::parse('15:30:45')->isMidday());
  732. }
  733. public function testHasFormat()
  734. {
  735. $this->assertTrue(Carbon::hasFormat('1975-05-01', 'Y-m-d'));
  736. $this->assertTrue(Carbon::hasFormat('12/30/2019', 'm/d/Y'));
  737. $this->assertTrue(Carbon::hasFormat('30/12/2019', 'd/m/Y'));
  738. $this->assertTrue(Carbon::hasFormat('Sun 21st', 'D jS'));
  739. $this->assertTrue(Carbon::hasFormat('2000-07-01T00:00:00+00:00', DateTime::ATOM));
  740. $this->assertTrue(Carbon::hasFormat('Y-01-30\\', '\\Y-m-d\\\\'));
  741. // @see https://github.com/briannesbitt/Carbon/issues/2180
  742. $this->assertTrue(Carbon::hasFormat('2020-09-01 12:00:00Europe/Moscow', 'Y-m-d H:i:se'));
  743. // Format failure
  744. $this->assertFalse(Carbon::hasFormat(null, 'd m Y'));
  745. $this->assertFalse(Carbon::hasFormat('1975-05-01', 'd m Y'));
  746. $this->assertFalse(Carbon::hasFormat('Foo 21st', 'D jS'));
  747. $this->assertFalse(Carbon::hasFormat('Sun 51st', 'D jS'));
  748. $this->assertFalse(Carbon::hasFormat('Sun 21xx', 'D jS'));
  749. // Regex failure
  750. $this->assertFalse(Carbon::hasFormat('1975-5-1', 'Y-m-d'));
  751. $this->assertFalse(Carbon::hasFormat('19-05-01', 'Y-m-d'));
  752. $this->assertFalse(Carbon::hasFormat('30/12/2019', 'm/d/Y'));
  753. $this->assertFalse(Carbon::hasFormat('12/30/2019', 'd/m/Y'));
  754. $this->assertTrue(Carbon::hasFormat('2012-12-04 22:59.32130', 'Y-m-d H:s.vi'));
  755. }
  756. public static function dataForFormatLetters(): Generator
  757. {
  758. yield ['d'];
  759. yield ['D'];
  760. yield ['j'];
  761. yield ['l'];
  762. yield ['N'];
  763. yield ['S'];
  764. yield ['w'];
  765. yield ['z'];
  766. yield ['W'];
  767. yield ['F'];
  768. yield ['m'];
  769. yield ['M'];
  770. yield ['n'];
  771. yield ['t'];
  772. yield ['L'];
  773. yield ['o'];
  774. yield ['Y'];
  775. yield ['y'];
  776. yield ['a'];
  777. yield ['A'];
  778. yield ['B'];
  779. yield ['g'];
  780. yield ['G'];
  781. yield ['h'];
  782. yield ['H'];
  783. yield ['i'];
  784. yield ['s'];
  785. yield ['u'];
  786. yield ['v'];
  787. yield ['e'];
  788. yield ['I'];
  789. yield ['O'];
  790. yield ['P'];
  791. yield ['T'];
  792. yield ['Z'];
  793. yield ['U'];
  794. yield ['c'];
  795. yield ['r'];
  796. }
  797. /**
  798. * @dataProvider \Tests\CarbonImmutable\IsTest::dataForFormatLetters
  799. */
  800. public function testHasFormatWithSingleLetter($letter)
  801. {
  802. $output = Carbon::now()->format($letter);
  803. if ($output === '1000' && $letter === 'v' && version_compare(PHP_VERSION, '7.2.12', '<')) {
  804. $output = '000';
  805. }
  806. $this->assertTrue(Carbon::hasFormat($output, $letter), "'$letter' format should match '$output'");
  807. }
  808. public function testIs()
  809. {
  810. $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('2019'));
  811. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('2018'));
  812. $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('2019-06'));
  813. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('2018-06'));
  814. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('2019-07'));
  815. $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('06-02'));
  816. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('06-03'));
  817. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('05-02'));
  818. $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('2019-06-02'));
  819. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('2019-06-03'));
  820. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('2019-05-02'));
  821. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('2020-06-02'));
  822. $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('Sunday'));
  823. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('Monday'));
  824. $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('June'));
  825. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('May'));
  826. $this->assertFalse(Carbon::parse('2023-10-01 00:00:00')->is('February'));
  827. $this->assertFalse(Carbon::parse('2023-10-01 00:00:00')->is('January'));
  828. $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('12:23'));
  829. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('12:26'));
  830. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('12:23:00'));
  831. $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('12h'));
  832. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('15h'));
  833. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('12:00'));
  834. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('15:00'));
  835. $this->assertTrue(Carbon::parse('2019-06-02 15:23:45')->is('3pm'));
  836. $this->assertFalse(Carbon::parse('2019-06-02 15:23:45')->is('4pm'));
  837. $this->assertFalse(Carbon::parse('2019-06-02 15:23:45')->is('3am'));
  838. $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('2019-06-02 12:23'));
  839. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('2019-06-03 12:23'));
  840. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('2019-06-02 15:23'));
  841. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('2019-06-02 12:33'));
  842. $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('2 June 2019'));
  843. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('1 June 2019'));
  844. $this->assertTrue(Carbon::parse('2019-06-02 12:23:45')->is('June 2019'));
  845. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('August 2019'));
  846. $this->assertFalse(Carbon::parse('2019-06-02 12:23:45')->is('June 2018'));
  847. }
  848. public function testHasFormatWithDots()
  849. {
  850. $this->assertTrue(Carbon::hasFormat('2020.09.09', 'Y.m.d'));
  851. $this->assertFalse(Carbon::hasFormat('2020009009', 'Y.m.d'));
  852. $this->assertFalse(Carbon::hasFormat('2020-09-09', 'Y.m.d'));
  853. $this->assertFalse(Carbon::hasFormat('2020*09*09', 'Y.m.d'));
  854. $this->assertFalse(Carbon::hasFormat('2020k09d09', 'Y.m.d'));
  855. }
  856. }