/vendor/nesbot/carbon/src/Carbon/Carbon.php

  1. <?php 
  2.  
  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.  
  12. namespace Carbon; 
  13.  
  14. use Closure; 
  15. use DateTime; 
  16. use DateTimeZone; 
  17. use DatePeriod; 
  18. use InvalidArgumentException; 
  19. use Symfony\Component\Translation\Translator; 
  20. use Symfony\Component\Translation\TranslatorInterface; 
  21. use Symfony\Component\Translation\Loader\ArrayLoader; 
  22.  
  23. /** 
  24. * A simple API extension for DateTime 
  25. * 
  26. * @property int $year 
  27. * @property int $yearIso 
  28. * @property int $month 
  29. * @property int $day 
  30. * @property int $hour 
  31. * @property int $minute 
  32. * @property int $second 
  33. * @property int $timestamp seconds since the Unix Epoch 
  34. * @property DateTimeZone $timezone the current timezone 
  35. * @property DateTimeZone $tz alias of timezone 
  36. * @property-read integer $micro 
  37. * @property-read integer $dayOfWeek 0 (for Sunday) through 6 (for Saturday) 
  38. * @property-read integer $dayOfYear 0 through 365 
  39. * @property-read integer $weekOfMonth 1 through 5 
  40. * @property-read integer $weekOfYear ISO-8601 week number of year, weeks starting on Monday 
  41. * @property-read integer $daysInMonth number of days in the given month 
  42. * @property-read integer $age does a diffInYears() with default parameters 
  43. * @property-read integer $quarter the quarter of this instance, 1 - 4 
  44. * @property-read integer $offset the timezone offset in seconds from UTC 
  45. * @property-read integer $offsetHours the timezone offset in hours from UTC 
  46. * @property-read boolean $dst daylight savings time indicator, true if DST, false otherwise 
  47. * @property-read boolean $local checks if the timezone is local, true if local, false otherwise 
  48. * @property-read boolean $utc checks if the timezone is UTC, true if UTC, false otherwise 
  49. * @property-read string $timezoneName 
  50. * @property-read string $tzName 
  51. */ 
  52. class Carbon extends DateTime 
  53. /** 
  54. * The day constants 
  55. */ 
  56. const SUNDAY = 0; 
  57. const MONDAY = 1; 
  58. const TUESDAY = 2; 
  59. const WEDNESDAY = 3; 
  60. const THURSDAY = 4; 
  61. const FRIDAY = 5; 
  62. const SATURDAY = 6; 
  63.  
  64. /** 
  65. * Names of days of the week. 
  66. * 
  67. * @var array 
  68. */ 
  69. protected static $days = array( 
  70. self::SUNDAY => 'Sunday',  
  71. self::MONDAY => 'Monday',  
  72. self::TUESDAY => 'Tuesday',  
  73. self::WEDNESDAY => 'Wednesday',  
  74. self::THURSDAY => 'Thursday',  
  75. self::FRIDAY => 'Friday',  
  76. self::SATURDAY => 'Saturday',  
  77. ); 
  78.  
  79. /** 
  80. * Terms used to detect if a time passed is a relative date for testing purposes 
  81. * 
  82. * @var array 
  83. */ 
  84. protected static $relativeKeywords = array( 
  85. 'this',  
  86. 'next',  
  87. 'last',  
  88. 'tomorrow',  
  89. 'yesterday',  
  90. '+',  
  91. '-',  
  92. 'first',  
  93. 'last',  
  94. 'ago',  
  95. ); 
  96.  
  97. /** 
  98. * Number of X in Y 
  99. */ 
  100. const YEARS_PER_CENTURY = 100; 
  101. const YEARS_PER_DECADE = 10; 
  102. const MONTHS_PER_YEAR = 12; 
  103. const WEEKS_PER_YEAR = 52; 
  104. const DAYS_PER_WEEK = 7; 
  105. const HOURS_PER_DAY = 24; 
  106. const MINUTES_PER_HOUR = 60; 
  107. const SECONDS_PER_MINUTE = 60; 
  108.  
  109. /** 
  110. * Default format to use for __toString method when type juggling occurs. 
  111. * 
  112. * @var string 
  113. */ 
  114. const DEFAULT_TO_STRING_FORMAT = 'Y-m-d H:i:s'; 
  115.  
  116. /** 
  117. * Format to use for __toString method when type juggling occurs. 
  118. * 
  119. * @var string 
  120. */ 
  121. protected static $toStringFormat = self::DEFAULT_TO_STRING_FORMAT; 
  122.  
  123. /** 
  124. * First day of week 
  125. * 
  126. * @var int 
  127. */ 
  128. protected static $weekStartsAt = self::MONDAY; 
  129.  
  130. /** 
  131. * Last day of week 
  132. * 
  133. * @var int 
  134. */ 
  135. protected static $weekEndsAt = self::SUNDAY; 
  136.  
  137. /** 
  138. * Days of weekend 
  139. * 
  140. * @var array 
  141. */ 
  142. protected static $weekendDays = array(self::SATURDAY, self::SUNDAY); 
  143.  
  144. /** 
  145. * A test Carbon instance to be returned when now instances are created 
  146. * 
  147. * @var Carbon 
  148. */ 
  149. protected static $testNow; 
  150.  
  151. /** 
  152. * A translator to ... er ... translate stuff 
  153. * 
  154. * @var TranslatorInterface 
  155. */ 
  156. protected static $translator; 
  157.  
  158. /** 
  159. * Creates a DateTimeZone from a string or a DateTimeZone 
  160. * 
  161. * @param DateTimeZone|string|null $object 
  162. * 
  163. * @throws InvalidArgumentException 
  164. * 
  165. * @return DateTimeZone 
  166. */ 
  167. protected static function safeCreateDateTimeZone($object) 
  168. if ($object === null) { 
  169. // Don't return null... avoid Bug #52063 in PHP <5.3.6 
  170. return new DateTimeZone(date_default_timezone_get()); 
  171.  
  172. if ($object instanceof DateTimeZone) { 
  173. return $object; 
  174.  
  175. $tz = @timezone_open((string) $object); 
  176.  
  177. if ($tz === false) { 
  178. throw new InvalidArgumentException('Unknown or bad timezone ('.$object.')'); 
  179.  
  180. return $tz; 
  181.  
  182. /////////////////////////////////////////////////////////////////// 
  183. //////////////////////////// CONSTRUCTORS ///////////////////////// 
  184. /////////////////////////////////////////////////////////////////// 
  185.  
  186. /** 
  187. * Create a new Carbon instance. 
  188. * 
  189. * Please see the testing aids section (specifically static::setTestNow()) 
  190. * for more on the possibility of this constructor returning a test instance. 
  191. * 
  192. * @param string|null $time 
  193. * @param DateTimeZone|string|null $tz 
  194. */ 
  195. public function __construct($time = null, $tz = null) 
  196. // If the class has a test now set and we are trying to create a now() 
  197. // instance then override as required 
  198. if (static::hasTestNow() && (empty($time) || $time === 'now' || static::hasRelativeKeywords($time))) { 
  199. $testInstance = clone static::getTestNow(); 
  200. if (static::hasRelativeKeywords($time)) { 
  201. $testInstance->modify($time); 
  202.  
  203. //shift the time according to the given time zone 
  204. if ($tz !== null && $tz !== static::getTestNow()->tz) { 
  205. $testInstance->setTimezone($tz); 
  206. } else { 
  207. $tz = $testInstance->tz; 
  208.  
  209. $time = $testInstance->toDateTimeString(); 
  210.  
  211. parent::__construct($time, static::safeCreateDateTimeZone($tz)); 
  212.  
  213. /** 
  214. * Create a Carbon instance from a DateTime one 
  215. * 
  216. * @param DateTime $dt 
  217. * 
  218. * @return static 
  219. */ 
  220. public static function instance(DateTime $dt) 
  221. return new static($dt->format('Y-m-d H:i:s.u'), $dt->getTimeZone()); 
  222.  
  223. /** 
  224. * Create a carbon instance from a string. This is an alias for the 
  225. * constructor that allows better fluent syntax as it allows you to do 
  226. * Carbon::parse('Monday next week')->fn() rather than 
  227. * (new Carbon('Monday next week'))->fn() 
  228. * 
  229. * @param string|null $time 
  230. * @param DateTimeZone|string|null $tz 
  231. * 
  232. * @return static 
  233. */ 
  234. public static function parse($time = null, $tz = null) 
  235. return new static($time, $tz); 
  236.  
  237. /** 
  238. * Get a Carbon instance for the current date and time 
  239. * 
  240. * @param DateTimeZone|string|null $tz 
  241. * 
  242. * @return static 
  243. */ 
  244. public static function now($tz = null) 
  245. return new static(null, $tz); 
  246.  
  247. /** 
  248. * Create a Carbon instance for today 
  249. * 
  250. * @param DateTimeZone|string|null $tz 
  251. * 
  252. * @return static 
  253. */ 
  254. public static function today($tz = null) 
  255. return static::now($tz)->startOfDay(); 
  256.  
  257. /** 
  258. * Create a Carbon instance for tomorrow 
  259. * 
  260. * @param DateTimeZone|string|null $tz 
  261. * 
  262. * @return static 
  263. */ 
  264. public static function tomorrow($tz = null) 
  265. return static::today($tz)->addDay(); 
  266.  
  267. /** 
  268. * Create a Carbon instance for yesterday 
  269. * 
  270. * @param DateTimeZone|string|null $tz 
  271. * 
  272. * @return static 
  273. */ 
  274. public static function yesterday($tz = null) 
  275. return static::today($tz)->subDay(); 
  276.  
  277. /** 
  278. * Create a Carbon instance for the greatest supported date. 
  279. * 
  280. * @return Carbon 
  281. */ 
  282. public static function maxValue() 
  283. if (PHP_INT_SIZE === 4) { 
  284. // 32 bit (and additionally Windows 64 bit) 
  285. return static::createFromTimestamp(PHP_INT_MAX); 
  286.  
  287. // 64 bit 
  288. return static::create(9999, 12, 31, 23, 59, 59); 
  289.  
  290. /** 
  291. * Create a Carbon instance for the lowest supported date. 
  292. * 
  293. * @return Carbon 
  294. */ 
  295. public static function minValue() 
  296. if (PHP_INT_SIZE === 4) { 
  297. // 32 bit (and additionally Windows 64 bit) 
  298. return static::createFromTimestamp(~PHP_INT_MAX); 
  299.  
  300. // 64 bit 
  301. return static::create(1, 1, 1, 0, 0, 0); 
  302.  
  303. /** 
  304. * Create a new Carbon instance from a specific date and time. 
  305. * 
  306. * If any of $year, $month or $day are set to null their now() values 
  307. * will be used. 
  308. * 
  309. * If $hour is null it will be set to its now() value and the default values 
  310. * for $minute and $second will be their now() values. 
  311. * If $hour is not null then the default values for $minute and $second 
  312. * will be 0. 
  313. * 
  314. * @param int|null $year 
  315. * @param int|null $month 
  316. * @param int|null $day 
  317. * @param int|null $hour 
  318. * @param int|null $minute 
  319. * @param int|null $second 
  320. * @param DateTimeZone|string|null $tz 
  321. * 
  322. * @return static 
  323. */ 
  324. public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $tz = null) 
  325. $year = $year === null ? date('Y') : $year; 
  326. $month = $month === null ? date('n') : $month; 
  327. $day = $day === null ? date('j') : $day; 
  328.  
  329. if ($hour === null) { 
  330. $hour = date('G'); 
  331. $minute = $minute === null ? date('i') : $minute; 
  332. $second = $second === null ? date('s') : $second; 
  333. } else { 
  334. $minute = $minute === null ? 0 : $minute; 
  335. $second = $second === null ? 0 : $second; 
  336.  
  337. return static::createFromFormat('Y-n-j G:i:s', sprintf('%s-%s-%s %s:%02s:%02s', $year, $month, $day, $hour, $minute, $second), $tz); 
  338.  
  339. /** 
  340. * Create a Carbon instance from just a date. The time portion is set to now. 
  341. * 
  342. * @param int|null $year 
  343. * @param int|null $month 
  344. * @param int|null $day 
  345. * @param DateTimeZone|string|null $tz 
  346. * 
  347. * @return static 
  348. */ 
  349. public static function createFromDate($year = null, $month = null, $day = null, $tz = null) 
  350. return static::create($year, $month, $day, null, null, null, $tz); 
  351.  
  352. /** 
  353. * Create a Carbon instance from just a time. The date portion is set to today. 
  354. * 
  355. * @param int|null $hour 
  356. * @param int|null $minute 
  357. * @param int|null $second 
  358. * @param DateTimeZone|string|null $tz 
  359. * 
  360. * @return static 
  361. */ 
  362. public static function createFromTime($hour = null, $minute = null, $second = null, $tz = null) 
  363. return static::create(null, null, null, $hour, $minute, $second, $tz); 
  364.  
  365. /** 
  366. * Create a Carbon instance from a specific format 
  367. * 
  368. * @param string $format 
  369. * @param string $time 
  370. * @param DateTimeZone|string|null $tz 
  371. * 
  372. * @throws InvalidArgumentException 
  373. * 
  374. * @return static 
  375. */ 
  376. public static function createFromFormat($format, $time, $tz = null) 
  377. if ($tz !== null) { 
  378. $dt = parent::createFromFormat($format, $time, static::safeCreateDateTimeZone($tz)); 
  379. } else { 
  380. $dt = parent::createFromFormat($format, $time); 
  381.  
  382. if ($dt instanceof DateTime) { 
  383. return static::instance($dt); 
  384.  
  385. $errors = static::getLastErrors(); 
  386. throw new InvalidArgumentException(implode(PHP_EOL, $errors['errors'])); 
  387.  
  388. /** 
  389. * Create a Carbon instance from a timestamp 
  390. * 
  391. * @param int $timestamp 
  392. * @param DateTimeZone|string|null $tz 
  393. * 
  394. * @return static 
  395. */ 
  396. public static function createFromTimestamp($timestamp, $tz = null) 
  397. return static::now($tz)->setTimestamp($timestamp); 
  398.  
  399. /** 
  400. * Create a Carbon instance from an UTC timestamp 
  401. * 
  402. * @param int $timestamp 
  403. * 
  404. * @return static 
  405. */ 
  406. public static function createFromTimestampUTC($timestamp) 
  407. return new static('@'.$timestamp); 
  408.  
  409. /** 
  410. * Get a copy of the instance 
  411. * 
  412. * @return static 
  413. */ 
  414. public function copy() 
  415. return static::instance($this); 
  416.  
  417. /////////////////////////////////////////////////////////////////// 
  418. ///////////////////////// GETTERS AND SETTERS ///////////////////// 
  419. /////////////////////////////////////////////////////////////////// 
  420.  
  421. /** 
  422. * Get a part of the Carbon object 
  423. * 
  424. * @param string $name 
  425. * 
  426. * @throws InvalidArgumentException 
  427. * 
  428. * @return string|int|DateTimeZone 
  429. */ 
  430. public function __get($name) 
  431. switch (true) { 
  432. case array_key_exists($name, $formats = array( 
  433. 'year' => 'Y',  
  434. 'yearIso' => 'o',  
  435. 'month' => 'n',  
  436. 'day' => 'j',  
  437. 'hour' => 'G',  
  438. 'minute' => 'i',  
  439. 'second' => 's',  
  440. 'micro' => 'u',  
  441. 'dayOfWeek' => 'w',  
  442. 'dayOfYear' => 'z',  
  443. 'weekOfYear' => 'W',  
  444. 'daysInMonth' => 't',  
  445. 'timestamp' => 'U',  
  446. )): 
  447. return (int) $this->format($formats[$name]); 
  448.  
  449. case $name === 'weekOfMonth': 
  450. return (int) ceil($this->day / static::DAYS_PER_WEEK); 
  451.  
  452. case $name === 'age': 
  453. return (int) $this->diffInYears(); 
  454.  
  455. case $name === 'quarter': 
  456. return (int) ceil($this->month / 3); 
  457.  
  458. case $name === 'offset': 
  459. return $this->getOffset(); 
  460.  
  461. case $name === 'offsetHours': 
  462. return $this->getOffset() / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR; 
  463.  
  464. case $name === 'dst': 
  465. return $this->format('I') === '1'; 
  466.  
  467. case $name === 'local': 
  468. return $this->offset === $this->copy()->setTimezone(date_default_timezone_get())->offset; 
  469.  
  470. case $name === 'utc': 
  471. return $this->offset === 0; 
  472.  
  473. case $name === 'timezone' || $name === 'tz': 
  474. return $this->getTimezone(); 
  475.  
  476. case $name === 'timezoneName' || $name === 'tzName': 
  477. return $this->getTimezone()->getName(); 
  478.  
  479. default: 
  480. throw new InvalidArgumentException(sprintf("Unknown getter '%s'", $name)); 
  481.  
  482. /** 
  483. * Check if an attribute exists on the object 
  484. * 
  485. * @param string $name 
  486. * 
  487. * @return bool 
  488. */ 
  489. public function __isset($name) 
  490. try { 
  491. $this->__get($name); 
  492. } catch (InvalidArgumentException $e) { 
  493. return false; 
  494.  
  495. return true; 
  496.  
  497. /** 
  498. * Set a part of the Carbon object 
  499. * 
  500. * @param string $name 
  501. * @param string|int|DateTimeZone $value 
  502. * 
  503. * @throws InvalidArgumentException 
  504. */ 
  505. public function __set($name, $value) 
  506. switch ($name) { 
  507. case 'year': 
  508. $this->setDate($value, $this->month, $this->day); 
  509. break; 
  510.  
  511. case 'month': 
  512. $this->setDate($this->year, $value, $this->day); 
  513. break; 
  514.  
  515. case 'day': 
  516. $this->setDate($this->year, $this->month, $value); 
  517. break; 
  518.  
  519. case 'hour': 
  520. $this->setTime($value, $this->minute, $this->second); 
  521. break; 
  522.  
  523. case 'minute': 
  524. $this->setTime($this->hour, $value, $this->second); 
  525. break; 
  526.  
  527. case 'second': 
  528. $this->setTime($this->hour, $this->minute, $value); 
  529. break; 
  530.  
  531. case 'timestamp': 
  532. parent::setTimestamp($value); 
  533. break; 
  534.  
  535. case 'timezone': 
  536. case 'tz': 
  537. $this->setTimezone($value); 
  538. break; 
  539.  
  540. default: 
  541. throw new InvalidArgumentException(sprintf("Unknown setter '%s'", $name)); 
  542.  
  543. /** 
  544. * Set the instance's year 
  545. * 
  546. * @param int $value 
  547. * 
  548. * @return static 
  549. */ 
  550. public function year($value) 
  551. $this->year = $value; 
  552.  
  553. return $this; 
  554.  
  555. /** 
  556. * Set the instance's month 
  557. * 
  558. * @param int $value 
  559. * 
  560. * @return static 
  561. */ 
  562. public function month($value) 
  563. $this->month = $value; 
  564.  
  565. return $this; 
  566.  
  567. /** 
  568. * Set the instance's day 
  569. * 
  570. * @param int $value 
  571. * 
  572. * @return static 
  573. */ 
  574. public function day($value) 
  575. $this->day = $value; 
  576.  
  577. return $this; 
  578.  
  579. /** 
  580. * Set the instance's hour 
  581. * 
  582. * @param int $value 
  583. * 
  584. * @return static 
  585. */ 
  586. public function hour($value) 
  587. $this->hour = $value; 
  588.  
  589. return $this; 
  590.  
  591. /** 
  592. * Set the instance's minute 
  593. * 
  594. * @param int $value 
  595. * 
  596. * @return static 
  597. */ 
  598. public function minute($value) 
  599. $this->minute = $value; 
  600.  
  601. return $this; 
  602.  
  603. /** 
  604. * Set the instance's second 
  605. * 
  606. * @param int $value 
  607. * 
  608. * @return static 
  609. */ 
  610. public function second($value) 
  611. $this->second = $value; 
  612.  
  613. return $this; 
  614.  
  615. /** 
  616. * Set the date and time all together 
  617. * 
  618. * @param int $year 
  619. * @param int $month 
  620. * @param int $day 
  621. * @param int $hour 
  622. * @param int $minute 
  623. * @param int $second 
  624. * 
  625. * @return static 
  626. */ 
  627. public function setDateTime($year, $month, $day, $hour, $minute, $second = 0) 
  628. return $this->setDate($year, $month, $day)->setTime($hour, $minute, $second); 
  629.  
  630. /** 
  631. * Set the time by time string 
  632. * 
  633. * @param string $time 
  634. * 
  635. * @return static 
  636. */ 
  637. public function setTimeFromTimeString($time) 
  638. $time = explode(":", $time); 
  639.  
  640. $hour = $time[0]; 
  641. $minute = isset($time[1]) ? $time[1] : 0; 
  642. $second = isset($time[2]) ? $time[2] : 0; 
  643.  
  644. return $this->setTime($hour, $minute, $second); 
  645.  
  646. /** 
  647. * Set the instance's timestamp 
  648. * 
  649. * @param int $value 
  650. * 
  651. * @return static 
  652. */ 
  653. public function timestamp($value) 
  654. $this->timestamp = $value; 
  655.  
  656. return $this; 
  657.  
  658. /** 
  659. * Alias for setTimezone() 
  660. * 
  661. * @param DateTimeZone|string $value 
  662. * 
  663. * @return static 
  664. */ 
  665. public function timezone($value) 
  666. return $this->setTimezone($value); 
  667.  
  668. /** 
  669. * Alias for setTimezone() 
  670. * 
  671. * @param DateTimeZone|string $value 
  672. * 
  673. * @return static 
  674. */ 
  675. public function tz($value) 
  676. return $this->setTimezone($value); 
  677.  
  678. /** 
  679. * Set the instance's timezone from a string or object 
  680. * 
  681. * @param DateTimeZone|string $value 
  682. * 
  683. * @return static 
  684. */ 
  685. public function setTimezone($value) 
  686. parent::setTimezone(static::safeCreateDateTimeZone($value)); 
  687.  
  688. return $this; 
  689.  
  690. /////////////////////////////////////////////////////////////////// 
  691. /////////////////////// WEEK SPECIAL DAYS ///////////////////////// 
  692. /////////////////////////////////////////////////////////////////// 
  693.  
  694. /** 
  695. * Get the first day of week 
  696. * 
  697. * @return int 
  698. */ 
  699. public static function getWeekStartsAt() 
  700. return static::$weekStartsAt; 
  701.  
  702. /** 
  703. * Set the first day of week 
  704. * 
  705. * @param int 
  706. */ 
  707. public static function setWeekStartsAt($day) 
  708. static::$weekStartsAt = $day; 
  709.  
  710. /** 
  711. * Get the last day of week 
  712. * 
  713. * @return int 
  714. */ 
  715. public static function getWeekEndsAt() 
  716. return static::$weekEndsAt; 
  717.  
  718. /** 
  719. * Set the first day of week 
  720. * 
  721. * @param int 
  722. */ 
  723. public static function setWeekEndsAt($day) 
  724. static::$weekEndsAt = $day; 
  725.  
  726. /** 
  727. * Get weekend days 
  728. * 
  729. * @return array 
  730. */ 
  731. public static function getWeekendDays() 
  732. return static::$weekendDays; 
  733.  
  734. /** 
  735. * Set weekend days 
  736. * 
  737. * @param array 
  738. */ 
  739. public static function setWeekendDays($days) 
  740. static::$weekendDays = $days; 
  741.  
  742. /////////////////////////////////////////////////////////////////// 
  743. ///////////////////////// TESTING AIDS //////////////////////////// 
  744. /////////////////////////////////////////////////////////////////// 
  745.  
  746. /** 
  747. * Set a Carbon instance (real or mock) to be returned when a "now" 
  748. * instance is created. The provided instance will be returned 
  749. * specifically under the following conditions: 
  750. * - A call to the static now() method, ex. Carbon::now() 
  751. * - When a null (or blank string) is passed to the constructor or parse(), ex. new Carbon(null) 
  752. * - When the string "now" is passed to the constructor or parse(), ex. new Carbon('now') 
  753. * 
  754. * Note the timezone parameter was left out of the examples above and 
  755. * has no affect as the mock value will be returned regardless of its value. 
  756. * 
  757. * To clear the test instance call this method using the default 
  758. * parameter of null. 
  759. * 
  760. * @param Carbon|null $testNow 
  761. */ 
  762. public static function setTestNow(Carbon $testNow = null) 
  763. static::$testNow = $testNow; 
  764.  
  765. /** 
  766. * Get the Carbon instance (real or mock) to be returned when a "now" 
  767. * instance is created. 
  768. * 
  769. * @return static the current instance used for testing 
  770. */ 
  771. public static function getTestNow() 
  772. return static::$testNow; 
  773.  
  774. /** 
  775. * Determine if there is a valid test instance set. A valid test instance 
  776. * is anything that is not null. 
  777. * 
  778. * @return bool true if there is a test instance, otherwise false 
  779. */ 
  780. public static function hasTestNow() 
  781. return static::getTestNow() !== null; 
  782.  
  783. /** 
  784. * Determine if there is a relative keyword in the time string, this is to 
  785. * create dates relative to now for test instances. e.g.: next tuesday 
  786. * 
  787. * @param string $time 
  788. * 
  789. * @return bool true if there is a keyword, otherwise false 
  790. */ 
  791. public static function hasRelativeKeywords($time) 
  792. // skip common format with a '-' in it 
  793. if (preg_match('/[0-9]{4}-[0-9]{1, 2}-[0-9]{1, 2}/', $time) !== 1) { 
  794. foreach (static::$relativeKeywords as $keyword) { 
  795. if (stripos($time, $keyword) !== false) { 
  796. return true; 
  797.  
  798. return false; 
  799.  
  800. /////////////////////////////////////////////////////////////////// 
  801. /////////////////////// LOCALIZATION ////////////////////////////// 
  802. /////////////////////////////////////////////////////////////////// 
  803.  
  804. /** 
  805. * Intialize the translator instance if necessary. 
  806. * 
  807. * @return TranslatorInterface 
  808. */ 
  809. protected static function translator() 
  810. if (static::$translator === null) { 
  811. static::$translator = new Translator('en'); 
  812. static::$translator->addLoader('array', new ArrayLoader()); 
  813. static::setLocale('en'); 
  814.  
  815. return static::$translator; 
  816.  
  817. /** 
  818. * Get the translator instance in use 
  819. * 
  820. * @return TranslatorInterface 
  821. */ 
  822. public static function getTranslator() 
  823. return static::translator(); 
  824.  
  825. /** 
  826. * Set the translator instance to use 
  827. * 
  828. * @param TranslatorInterface $translator 
  829. */ 
  830. public static function setTranslator(TranslatorInterface $translator) 
  831. static::$translator = $translator; 
  832.  
  833. /** 
  834. * Get the current translator locale 
  835. * 
  836. * @return string 
  837. */ 
  838. public static function getLocale() 
  839. return static::translator()->getLocale(); 
  840.  
  841. /** 
  842. * Set the current translator locale 
  843. * 
  844. * @param string $locale 
  845. */ 
  846. public static function setLocale($locale) 
  847. static::translator()->setLocale($locale); 
  848.  
  849. // Ensure the locale has been loaded. 
  850. static::translator()->addResource('array', require __DIR__.'/Lang/'.$locale.'.php', $locale); 
  851.  
  852. /////////////////////////////////////////////////////////////////// 
  853. /////////////////////// STRING FORMATTING ///////////////////////// 
  854. /////////////////////////////////////////////////////////////////// 
  855.  
  856. /** 
  857. * Format the instance with the current locale. You can set the current 
  858. * locale using setlocale() http://php.net/setlocale. 
  859. * 
  860. * @param string $format 
  861. * 
  862. * @return string 
  863. */ 
  864. public function formatLocalized($format) 
  865. // Check for Windows to find and replace the %e 
  866. // modifier correctly 
  867. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { 
  868. $format = preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $format); 
  869.  
  870. return strftime($format, strtotime($this)); 
  871.  
  872. /** 
  873. * Reset the format used to the default when type juggling a Carbon instance to a string 
  874. */ 
  875. public static function resetToStringFormat() 
  876. static::setToStringFormat(static::DEFAULT_TO_STRING_FORMAT); 
  877.  
  878. /** 
  879. * Set the default format used when type juggling a Carbon instance to a string 
  880. * 
  881. * @param string $format 
  882. */ 
  883. public static function setToStringFormat($format) 
  884. static::$toStringFormat = $format; 
  885.  
  886. /** 
  887. * Format the instance as a string using the set format 
  888. * 
  889. * @return string 
  890. */ 
  891. public function __toString() 
  892. return $this->format(static::$toStringFormat); 
  893.  
  894. /** 
  895. * Format the instance as date 
  896. * 
  897. * @return string 
  898. */ 
  899. public function toDateString() 
  900. return $this->format('Y-m-d'); 
  901.  
  902. /** 
  903. * Format the instance as a readable date 
  904. * 
  905. * @return string 
  906. */ 
  907. public function toFormattedDateString() 
  908. return $this->format('M j, Y'); 
  909.  
  910. /** 
  911. * Format the instance as time 
  912. * 
  913. * @return string 
  914. */ 
  915. public function toTimeString() 
  916. return $this->format('H:i:s'); 
  917.  
  918. /** 
  919. * Format the instance as date and time 
  920. * 
  921. * @return string 
  922. */ 
  923. public function toDateTimeString() 
  924. return $this->format('Y-m-d H:i:s'); 
  925.  
  926. /** 
  927. * Format the instance with day, date and time 
  928. * 
  929. * @return string 
  930. */ 
  931. public function toDayDateTimeString() 
  932. return $this->format('D, M j, Y g:i A'); 
  933.  
  934. /** 
  935. * Format the instance as ATOM 
  936. * 
  937. * @return string 
  938. */ 
  939. public function toAtomString() 
  940. return $this->format(static::ATOM); 
  941.  
  942. /** 
  943. * Format the instance as COOKIE 
  944. * 
  945. * @return string 
  946. */ 
  947. public function toCookieString() 
  948. return $this->format(static::COOKIE); 
  949.  
  950. /** 
  951. * Format the instance as ISO8601 
  952. * 
  953. * @return string 
  954. */ 
  955. public function toIso8601String() 
  956. return $this->format(static::ISO8601); 
  957.  
  958. /** 
  959. * Format the instance as RFC822 
  960. * 
  961. * @return string 
  962. */ 
  963. public function toRfc822String() 
  964. return $this->format(static::RFC822); 
  965.  
  966. /** 
  967. * Format the instance as RFC850 
  968. * 
  969. * @return string 
  970. */ 
  971. public function toRfc850String() 
  972. return $this->format(static::RFC850); 
  973.  
  974. /** 
  975. * Format the instance as RFC1036 
  976. * 
  977. * @return string 
  978. */ 
  979. public function toRfc1036String() 
  980. return $this->format(static::RFC1036); 
  981.  
  982. /** 
  983. * Format the instance as RFC1123 
  984. * 
  985. * @return string 
  986. */ 
  987. public function toRfc1123String() 
  988. return $this->format(static::RFC1123); 
  989.  
  990. /** 
  991. * Format the instance as RFC2822 
  992. * 
  993. * @return string 
  994. */ 
  995. public function toRfc2822String() 
  996. return $this->format(static::RFC2822); 
  997.  
  998. /** 
  999. * Format the instance as RFC3339 
  1000. * 
  1001. * @return string 
  1002. */ 
  1003. public function toRfc3339String() 
  1004. return $this->format(static::RFC3339); 
  1005.  
  1006. /** 
  1007. * Format the instance as RSS 
  1008. * 
  1009. * @return string 
  1010. */ 
  1011. public function toRssString() 
  1012. return $this->format(static::RSS); 
  1013.  
  1014. /** 
  1015. * Format the instance as W3C 
  1016. * 
  1017. * @return string 
  1018. */ 
  1019. public function toW3cString() 
  1020. return $this->format(static::W3C); 
  1021.  
  1022. /////////////////////////////////////////////////////////////////// 
  1023. ////////////////////////// COMPARISONS //////////////////////////// 
  1024. /////////////////////////////////////////////////////////////////// 
  1025.  
  1026. /** 
  1027. * Determines if the instance is equal to another 
  1028. * 
  1029. * @param Carbon $dt 
  1030. * 
  1031. * @return bool 
  1032. */ 
  1033. public function eq(Carbon $dt) 
  1034. return $this == $dt; 
  1035.  
  1036. /** 
  1037. * Determines if the instance is not equal to another 
  1038. * 
  1039. * @param Carbon $dt 
  1040. * 
  1041. * @return bool 
  1042. */ 
  1043. public function ne(Carbon $dt) 
  1044. return !$this->eq($dt); 
  1045.  
  1046. /** 
  1047. * Determines if the instance is greater (after) than another 
  1048. * 
  1049. * @param Carbon $dt 
  1050. * 
  1051. * @return bool 
  1052. */ 
  1053. public function gt(Carbon $dt) 
  1054. return $this > $dt; 
  1055.  
  1056. /** 
  1057. * Determines if the instance is greater (after) than or equal to another 
  1058. * 
  1059. * @param Carbon $dt 
  1060. * 
  1061. * @return bool 
  1062. */ 
  1063. public function gte(Carbon $dt) 
  1064. return $this >= $dt; 
  1065.  
  1066. /** 
  1067. * Determines if the instance is less (before) than another 
  1068. * 
  1069. * @param Carbon $dt 
  1070. * 
  1071. * @return bool 
  1072. */ 
  1073. public function lt(Carbon $dt) 
  1074. return $this < $dt; 
  1075.  
  1076. /** 
  1077. * Determines if the instance is less (before) or equal to another 
  1078. * 
  1079. * @param Carbon $dt 
  1080. * 
  1081. * @return bool 
  1082. */ 
  1083. public function lte(Carbon $dt) 
  1084. return $this <= $dt; 
  1085.  
  1086. /** 
  1087. * Determines if the instance is between two others 
  1088. * 
  1089. * @param Carbon $dt1 
  1090. * @param Carbon $dt2 
  1091. * @param bool $equal Indicates if a > and < comparison should be used or <= or >= 
  1092. * 
  1093. * @return bool 
  1094. */ 
  1095. public function between(Carbon $dt1, Carbon $dt2, $equal = true) 
  1096. if ($dt1->gt($dt2)) { 
  1097. $temp = $dt1; 
  1098. $dt1 = $dt2; 
  1099. $dt2 = $temp; 
  1100.  
  1101. if ($equal) { 
  1102. return $this->gte($dt1) && $this->lte($dt2); 
  1103.  
  1104. return $this->gt($dt1) && $this->lt($dt2); 
  1105.  
  1106. /** 
  1107. * Get the closest date from the instance. 
  1108. * 
  1109. * @param Carbon $dt1 
  1110. * @param Carbon $dt2 
  1111. * 
  1112. * @return static 
  1113. */ 
  1114. public function closest(Carbon $dt1, Carbon $dt2) 
  1115. return $this->diffInSeconds($dt1) < $this->diffInSeconds($dt2) ? $dt1 : $dt2; 
  1116.  
  1117. /** 
  1118. * Get the farthest date from the instance. 
  1119. * 
  1120. * @param Carbon $dt1 
  1121. * @param Carbon $dt2 
  1122. * 
  1123. * @return static 
  1124. */ 
  1125. public function farthest(Carbon $dt1, Carbon $dt2) 
  1126. return $this->diffInSeconds($dt1) > $this->diffInSeconds($dt2) ? $dt1 : $dt2; 
  1127.  
  1128. /** 
  1129. * Get the minimum instance between a given instance (default now) and the current instance. 
  1130. * 
  1131. * @param Carbon|null $dt 
  1132. * 
  1133. * @return static 
  1134. */ 
  1135. public function min(Carbon $dt = null) 
  1136. $dt = $dt ?: static::now($this->tz); 
  1137.  
  1138. return $this->lt($dt) ? $this : $dt; 
  1139.  
  1140. /** 
  1141. * Get the maximum instance between a given instance (default now) and the current instance. 
  1142. * 
  1143. * @param Carbon|null $dt 
  1144. * 
  1145. * @return static 
  1146. */ 
  1147. public function max(Carbon $dt = null) 
  1148. $dt = $dt ?: static::now($this->tz); 
  1149.  
  1150. return $this->gt($dt) ? $this : $dt; 
  1151.  
  1152. /** 
  1153. * Determines if the instance is a weekday 
  1154. * 
  1155. * @return bool 
  1156. */ 
  1157. public function isWeekday() 
  1158. return !$this->isWeekend(); 
  1159.  
  1160. /** 
  1161. * Determines if the instance is a weekend day 
  1162. * 
  1163. * @return bool 
  1164. */ 
  1165. public function isWeekend() 
  1166. return in_array($this->dayOfWeek, self::$weekendDays); 
  1167.  
  1168. /** 
  1169. * Determines if the instance is yesterday 
  1170. * 
  1171. * @return bool 
  1172. */ 
  1173. public function isYesterday() 
  1174. return $this->toDateString() === static::yesterday($this->tz)->toDateString(); 
  1175.  
  1176. /** 
  1177. * Determines if the instance is today 
  1178. * 
  1179. * @return bool 
  1180. */ 
  1181. public function isToday() 
  1182. return $this->toDateString() === static::now($this->tz)->toDateString(); 
  1183.  
  1184. /** 
  1185. * Determines if the instance is tomorrow 
  1186. * 
  1187. * @return bool 
  1188. */ 
  1189. public function isTomorrow() 
  1190. return $this->toDateString() === static::tomorrow($this->tz)->toDateString(); 
  1191.  
  1192. /** 
  1193. * Determines if the instance is in the future, ie. greater (after) than now 
  1194. * 
  1195. * @return bool 
  1196. */ 
  1197. public function isFuture() 
  1198. return $this->gt(static::now($this->tz)); 
  1199.  
  1200. /** 
  1201. * Determines if the instance is in the past, ie. less (before) than now 
  1202. * 
  1203. * @return bool 
  1204. */ 
  1205. public function isPast() 
  1206. return $this->lt(static::now($this->tz)); 
  1207.  
  1208. /** 
  1209. * Determines if the instance is a leap year 
  1210. * 
  1211. * @return bool 
  1212. */ 
  1213. public function isLeapYear() 
  1214. return $this->format('L') === '1'; 
  1215.  
  1216. /** 
  1217. * Checks if the passed in date is the same day as the instance current day. 
  1218. * 
  1219. * @param Carbon $dt 
  1220. * 
  1221. * @return bool 
  1222. */ 
  1223. public function isSameDay(Carbon $dt) 
  1224. return $this->toDateString() === $dt->toDateString(); 
  1225.  
  1226. /** 
  1227. * Checks if this day is a Sunday. 
  1228. * 
  1229. * @return bool 
  1230. */ 
  1231. public function isSunday() 
  1232. return $this->dayOfWeek === static::SUNDAY; 
  1233.  
  1234. /** 
  1235. * Checks if this day is a Monday. 
  1236. * 
  1237. * @return bool 
  1238. */ 
  1239. public function isMonday() 
  1240. return $this->dayOfWeek === static::MONDAY; 
  1241.  
  1242. /** 
  1243. * Checks if this day is a Tuesday. 
  1244. * 
  1245. * @return bool 
  1246. */ 
  1247. public function isTuesday() 
  1248. return $this->dayOfWeek === static::TUESDAY; 
  1249.  
  1250. /** 
  1251. * Checks if this day is a Wednesday. 
  1252. * 
  1253. * @return bool 
  1254. */ 
  1255. public function isWednesday() 
  1256. return $this->dayOfWeek === static::WEDNESDAY; 
  1257.  
  1258. /** 
  1259. * Checks if this day is a Thursday. 
  1260. * 
  1261. * @return bool 
  1262. */ 
  1263. public function isThursday() 
  1264. return $this->dayOfWeek === static::THURSDAY; 
  1265.  
  1266. /** 
  1267. * Checks if this day is a Friday. 
  1268. * 
  1269. * @return bool 
  1270. */ 
  1271. public function isFriday() 
  1272. return $this->dayOfWeek === static::FRIDAY; 
  1273.  
  1274. /** 
  1275. * Checks if this day is a Saturday. 
  1276. * 
  1277. * @return bool 
  1278. */ 
  1279. public function isSaturday() 
  1280. return $this->dayOfWeek === static::SATURDAY; 
  1281.  
  1282. /////////////////////////////////////////////////////////////////// 
  1283. /////////////////// ADDITIONS AND SUBTRACTIONS //////////////////// 
  1284. /////////////////////////////////////////////////////////////////// 
  1285.  
  1286. /** 
  1287. * Add years to the instance. Positive $value travel forward while 
  1288. * negative $value travel into the past. 
  1289. * 
  1290. * @param int $value 
  1291. * 
  1292. * @return static 
  1293. */ 
  1294. public function addYears($value) 
  1295. return $this->modify((int) $value.' year'); 
  1296.  
  1297. /** 
  1298. * Add a year to the instance 
  1299. * 
  1300. * @param int $value 
  1301. * 
  1302. * @return static 
  1303. */ 
  1304. public function addYear($value = 1) 
  1305. return $this->addYears($value); 
  1306.  
  1307. /** 
  1308. * Remove a year from the instance 
  1309. * 
  1310. * @param int $value 
  1311. * 
  1312. * @return static 
  1313. */ 
  1314. public function subYear($value = 1) 
  1315. return $this->subYears($value); 
  1316.  
  1317. /** 
  1318. * Remove years from the instance. 
  1319. * 
  1320. * @param int $value 
  1321. * 
  1322. * @return static 
  1323. */ 
  1324. public function subYears($value) 
  1325. return $this->addYears(-1 * $value); 
  1326.  
  1327. /** 
  1328. * Add months to the instance. Positive $value travels forward while 
  1329. * negative $value travels into the past. 
  1330. * 
  1331. * @param int $value 
  1332. * 
  1333. * @return static 
  1334. */ 
  1335. public function addMonths($value) 
  1336. return $this->modify((int) $value.' month'); 
  1337.  
  1338. /** 
  1339. * Add a month to the instance 
  1340. * 
  1341. * @param int $value 
  1342. * 
  1343. * @return static 
  1344. */ 
  1345. public function addMonth($value = 1) 
  1346. return $this->addMonths($value); 
  1347.  
  1348. /** 
  1349. * Remove a month from the instance 
  1350. * 
  1351. * @param int $value 
  1352. * 
  1353. * @return static 
  1354. */ 
  1355. public function subMonth($value = 1) 
  1356. return $this->subMonths($value); 
  1357.  
  1358. /** 
  1359. * Remove months from the instance 
  1360. * 
  1361. * @param int $value 
  1362. * 
  1363. * @return static 
  1364. */ 
  1365. public function subMonths($value) 
  1366. return $this->addMonths(-1 * $value); 
  1367.  
  1368. /** 
  1369. * Add months without overflowing to the instance. Positive $value 
  1370. * travels forward while negative $value travels into the past. 
  1371. * 
  1372. * @param int $value 
  1373. * 
  1374. * @return static 
  1375. */ 
  1376. public function addMonthsNoOverflow($value) 
  1377. $date = $this->copy()->addMonths($value); 
  1378.  
  1379. if ($date->day !== $this->day) { 
  1380. $date->day(1)->subMonth()->day($date->daysInMonth); 
  1381.  
  1382. return $date; 
  1383.  
  1384. /** 
  1385. * Add a month with no overflow to the instance 
  1386. * 
  1387. * @param int $value 
  1388. * 
  1389. * @return static 
  1390. */ 
  1391. public function addMonthNoOverflow($value = 1) 
  1392. return $this->addMonthsNoOverflow($value); 
  1393.  
  1394. /** 
  1395. * Remove a month with no overflow from the instance 
  1396. * 
  1397. * @param int $value 
  1398. * 
  1399. * @return static 
  1400. */ 
  1401. public function subMonthNoOverflow($value = 1) 
  1402. return $this->subMonthsNoOverflow($value); 
  1403.  
  1404. /** 
  1405. * Remove months with no overflow from the instance 
  1406. * 
  1407. * @param int $value 
  1408. * 
  1409. * @return static 
  1410. */ 
  1411. public function subMonthsNoOverflow($value) 
  1412. return $this->addMonthsNoOverflow(-1 * $value); 
  1413.  
  1414. /** 
  1415. * Add days to the instance. Positive $value travels forward while 
  1416. * negative $value travels into the past. 
  1417. * 
  1418. * @param int $value 
  1419. * 
  1420. * @return static 
  1421. */ 
  1422. public function addDays($value) 
  1423. return $this->modify((int) $value.' day'); 
  1424.  
  1425. /** 
  1426. * Add a day to the instance 
  1427. * 
  1428. * @param int $value 
  1429. * 
  1430. * @return static 
  1431. */ 
  1432. public function addDay($value = 1) 
  1433. return $this->addDays($value); 
  1434.  
  1435. /** 
  1436. * Remove a day from the instance 
  1437. * 
  1438. * @param int $value 
  1439. * 
  1440. * @return static 
  1441. */ 
  1442. public function subDay($value = 1) 
  1443. return $this->subDays($value); 
  1444.  
  1445. /** 
  1446. * Remove days from the instance 
  1447. * 
  1448. * @param int $value 
  1449. * 
  1450. * @return static 
  1451. */ 
  1452. public function subDays($value) 
  1453. return $this->addDays(-1 * $value); 
  1454.  
  1455. /** 
  1456. * Add weekdays to the instance. Positive $value travels forward while 
  1457. * negative $value travels into the past. 
  1458. * 
  1459. * @param int $value 
  1460. * 
  1461. * @return static 
  1462. */ 
  1463. public function addWeekdays($value) 
  1464. return $this->modify((int) $value.' weekday'); 
  1465.  
  1466. /** 
  1467. * Add a weekday to the instance 
  1468. * 
  1469. * @param int $value 
  1470. * 
  1471. * @return static 
  1472. */ 
  1473. public function addWeekday($value = 1) 
  1474. return $this->addWeekdays($value); 
  1475.  
  1476. /** 
  1477. * Remove a weekday from the instance 
  1478. * 
  1479. * @param int $value 
  1480. * 
  1481. * @return static 
  1482. */ 
  1483. public function subWeekday($value = 1) 
  1484. return $this->subWeekdays($value); 
  1485.  
  1486. /** 
  1487. * Remove weekdays from the instance 
  1488. * 
  1489. * @param int $value 
  1490. * 
  1491. * @return static 
  1492. */ 
  1493. public function subWeekdays($value) 
  1494. return $this->addWeekdays(-1 * $value); 
  1495.  
  1496. /** 
  1497. * Add weeks to the instance. Positive $value travels forward while 
  1498. * negative $value travels into the past. 
  1499. * 
  1500. * @param int $value 
  1501. * 
  1502. * @return static 
  1503. */ 
  1504. public function addWeeks($value) 
  1505. return $this->modify((int) $value.' week'); 
  1506.  
  1507. /** 
  1508. * Add a week to the instance 
  1509. * 
  1510. * @param int $value 
  1511. * 
  1512. * @return static 
  1513. */ 
  1514. public function addWeek($value = 1) 
  1515. return $this->addWeeks($value); 
  1516.  
  1517. /** 
  1518. * Remove a week from the instance 
  1519. * 
  1520. * @param int $value 
  1521. * 
  1522. * @return static 
  1523. */ 
  1524. public function subWeek($value = 1) 
  1525. return $this->subWeeks($value); 
  1526.  
  1527. /** 
  1528. * Remove weeks to the instance 
  1529. * 
  1530. * @param int $value 
  1531. * 
  1532. * @return static 
  1533. */ 
  1534. public function subWeeks($value) 
  1535. return $this->addWeeks(-1 * $value); 
  1536.  
  1537. /** 
  1538. * Add hours to the instance. Positive $value travels forward while 
  1539. * negative $value travels into the past. 
  1540. * 
  1541. * @param int $value 
  1542. * 
  1543. * @return static 
  1544. */ 
  1545. public function addHours($value) 
  1546. return $this->modify((int) $value.' hour'); 
  1547.  
  1548. /** 
  1549. * Add an hour to the instance 
  1550. * 
  1551. * @param int $value 
  1552. * 
  1553. * @return static 
  1554. */ 
  1555. public function addHour($value = 1) 
  1556. return $this->addHours($value); 
  1557.  
  1558. /** 
  1559. * Remove an hour from the instance 
  1560. * 
  1561. * @param int $value 
  1562. * 
  1563. * @return static 
  1564. */ 
  1565. public function subHour($value = 1) 
  1566. return $this->subHours($value); 
  1567.  
  1568. /** 
  1569. * Remove hours from the instance 
  1570. * 
  1571. * @param int $value 
  1572. * 
  1573. * @return static 
  1574. */ 
  1575. public function subHours($value) 
  1576. return $this->addHours(-1 * $value); 
  1577.  
  1578. /** 
  1579. * Add minutes to the instance. Positive $value travels forward while 
  1580. * negative $value travels into the past. 
  1581. * 
  1582. * @param int $value 
  1583. * 
  1584. * @return static 
  1585. */ 
  1586. public function addMinutes($value) 
  1587. return $this->modify((int) $value.' minute'); 
  1588.  
  1589. /** 
  1590. * Add a minute to the instance 
  1591. * 
  1592. * @param int $value 
  1593. * 
  1594. * @return static 
  1595. */ 
  1596. public function addMinute($value = 1) 
  1597. return $this->addMinutes($value); 
  1598.  
  1599. /** 
  1600. * Remove a minute from the instance 
  1601. * 
  1602. * @param int $value 
  1603. * 
  1604. * @return static 
  1605. */ 
  1606. public function subMinute($value = 1) 
  1607. return $this->subMinutes($value); 
  1608.  
  1609. /** 
  1610. * Remove minutes from the instance 
  1611. * 
  1612. * @param int $value 
  1613. * 
  1614. * @return static 
  1615. */ 
  1616. public function subMinutes($value) 
  1617. return $this->addMinutes(-1 * $value); 
  1618.  
  1619. /** 
  1620. * Add seconds to the instance. Positive $value travels forward while 
  1621. * negative $value travels into the past. 
  1622. * 
  1623. * @param int $value 
  1624. * 
  1625. * @return static 
  1626. */ 
  1627. public function addSeconds($value) 
  1628. return $this->modify((int) $value.' second'); 
  1629.  
  1630. /** 
  1631. * Add a second to the instance 
  1632. * 
  1633. * @param int $value 
  1634. * 
  1635. * @return static 
  1636. */ 
  1637. public function addSecond($value = 1) 
  1638. return $this->addSeconds($value); 
  1639.  
  1640. /** 
  1641. * Remove a second from the instance 
  1642. * 
  1643. * @param int $value 
  1644. * 
  1645. * @return static 
  1646. */ 
  1647. public function subSecond($value = 1) 
  1648. return $this->subSeconds($value); 
  1649.  
  1650. /** 
  1651. * Remove seconds from the instance 
  1652. * 
  1653. * @param int $value 
  1654. * 
  1655. * @return static 
  1656. */ 
  1657. public function subSeconds($value) 
  1658. return $this->addSeconds(-1 * $value); 
  1659.  
  1660. /////////////////////////////////////////////////////////////////// 
  1661. /////////////////////////// DIFFERENCES /////////////////////////// 
  1662. /////////////////////////////////////////////////////////////////// 
  1663.  
  1664. /** 
  1665. * Get the difference in years 
  1666. * 
  1667. * @param Carbon|null $dt 
  1668. * @param bool $abs Get the absolute of the difference 
  1669. * 
  1670. * @return int 
  1671. */ 
  1672. public function diffInYears(Carbon $dt = null, $abs = true) 
  1673. $dt = $dt ?: static::now($this->tz); 
  1674.  
  1675. return (int) $this->diff($dt, $abs)->format('%r%y'); 
  1676.  
  1677. /** 
  1678. * Get the difference in months 
  1679. * 
  1680. * @param Carbon|null $dt 
  1681. * @param bool $abs Get the absolute of the difference 
  1682. * 
  1683. * @return int 
  1684. */ 
  1685. public function diffInMonths(Carbon $dt = null, $abs = true) 
  1686. $dt = $dt ?: static::now($this->tz); 
  1687.  
  1688. return $this->diffInYears($dt, $abs) * static::MONTHS_PER_YEAR + (int) $this->diff($dt, $abs)->format('%r%m'); 
  1689.  
  1690. /** 
  1691. * Get the difference in weeks 
  1692. * 
  1693. * @param Carbon|null $dt 
  1694. * @param bool $abs Get the absolute of the difference 
  1695. * 
  1696. * @return int 
  1697. */ 
  1698. public function diffInWeeks(Carbon $dt = null, $abs = true) 
  1699. return (int) ($this->diffInDays($dt, $abs) / static::DAYS_PER_WEEK); 
  1700.  
  1701. /** 
  1702. * Get the difference in days 
  1703. * 
  1704. * @param Carbon|null $dt 
  1705. * @param bool $abs Get the absolute of the difference 
  1706. * 
  1707. * @return int 
  1708. */ 
  1709. public function diffInDays(Carbon $dt = null, $abs = true) 
  1710. $dt = $dt ?: static::now($this->tz); 
  1711.  
  1712. return (int) $this->diff($dt, $abs)->format('%r%a'); 
  1713.  
  1714. /** 
  1715. * Get the difference in days using a filter closure 
  1716. * 
  1717. * @param Closure $callback 
  1718. * @param Carbon|null $dt 
  1719. * @param bool $abs Get the absolute of the difference 
  1720. * 
  1721. * @return int 
  1722. */ 
  1723. public function diffInDaysFiltered(Closure $callback, Carbon $dt = null, $abs = true) 
  1724. return $this->diffFiltered(CarbonInterval::day(), $callback, $dt, $abs); 
  1725.  
  1726. /** 
  1727. * Get the difference in hours using a filter closure 
  1728. * 
  1729. * @param Closure $callback 
  1730. * @param Carbon|null $dt 
  1731. * @param bool $abs Get the absolute of the difference 
  1732. * 
  1733. * @return int 
  1734. */ 
  1735. public function diffInHoursFiltered(Closure $callback, Carbon $dt = null, $abs = true) 
  1736. return $this->diffFiltered(CarbonInterval::hour(), $callback, $dt, $abs); 
  1737.  
  1738. /** 
  1739. * Get the difference by the given interval using a filter closure 
  1740. * 
  1741. * @param CarbonInterval $ci An interval to traverse by 
  1742. * @param Closure $callback 
  1743. * @param Carbon|null $dt 
  1744. * @param bool $abs Get the absolute of the difference 
  1745. * 
  1746. * @return int 
  1747. */ 
  1748. public function diffFiltered(CarbonInterval $ci, Closure $callback, Carbon $dt = null, $abs = true) 
  1749. $start = $this; 
  1750. $end = $dt ?: static::now($this->tz); 
  1751. $inverse = false; 
  1752.  
  1753. if ($end < $start) { 
  1754. $start = $end; 
  1755. $end = $this; 
  1756. $inverse = true; 
  1757.  
  1758. $period = new DatePeriod($start, $ci, $end); 
  1759. $vals = array_filter(iterator_to_array($period), function (DateTime $date) use ($callback) { 
  1760. return call_user_func($callback, Carbon::instance($date)); 
  1761. }); 
  1762.  
  1763. $diff = count($vals); 
  1764.  
  1765. return $inverse && !$abs ? -$diff : $diff; 
  1766.  
  1767. /** 
  1768. * Get the difference in weekdays 
  1769. * 
  1770. * @param Carbon|null $dt 
  1771. * @param bool $abs Get the absolute of the difference 
  1772. * 
  1773. * @return int 
  1774. */ 
  1775. public function diffInWeekdays(Carbon $dt = null, $abs = true) 
  1776. return $this->diffInDaysFiltered(function (Carbon $date) { 
  1777. return $date->isWeekday(); 
  1778. }, $dt, $abs); 
  1779.  
  1780. /** 
  1781. * Get the difference in weekend days using a filter 
  1782. * 
  1783. * @param Carbon|null $dt 
  1784. * @param bool $abs Get the absolute of the difference 
  1785. * 
  1786. * @return int 
  1787. */ 
  1788. public function diffInWeekendDays(Carbon $dt = null, $abs = true) 
  1789. return $this->diffInDaysFiltered(function (Carbon $date) { 
  1790. return $date->isWeekend(); 
  1791. }, $dt, $abs); 
  1792.  
  1793. /** 
  1794. * Get the difference in hours 
  1795. * 
  1796. * @param Carbon|null $dt 
  1797. * @param bool $abs Get the absolute of the difference 
  1798. * 
  1799. * @return int 
  1800. */ 
  1801. public function diffInHours(Carbon $dt = null, $abs = true) 
  1802. return (int) ($this->diffInSeconds($dt, $abs) / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR); 
  1803.  
  1804. /** 
  1805. * Get the difference in minutes 
  1806. * 
  1807. * @param Carbon|null $dt 
  1808. * @param bool $abs Get the absolute of the difference 
  1809. * 
  1810. * @return int 
  1811. */ 
  1812. public function diffInMinutes(Carbon $dt = null, $abs = true) 
  1813. return (int) ($this->diffInSeconds($dt, $abs) / static::SECONDS_PER_MINUTE); 
  1814.  
  1815. /** 
  1816. * Get the difference in seconds 
  1817. * 
  1818. * @param Carbon|null $dt 
  1819. * @param bool $abs Get the absolute of the difference 
  1820. * 
  1821. * @return int 
  1822. */ 
  1823. public function diffInSeconds(Carbon $dt = null, $abs = true) 
  1824. $dt = $dt ?: static::now($this->tz); 
  1825. $value = $dt->getTimestamp() - $this->getTimestamp(); 
  1826.  
  1827. return $abs ? abs($value) : $value; 
  1828.  
  1829. /** 
  1830. * The number of seconds since midnight. 
  1831. * 
  1832. * @return int 
  1833. */ 
  1834. public function secondsSinceMidnight() 
  1835. return $this->diffInSeconds($this->copy()->startOfDay()); 
  1836.  
  1837. /** 
  1838. * The number of seconds until 23:23:59. 
  1839. * 
  1840. * @return int 
  1841. */ 
  1842. public function secondsUntilEndOfDay() 
  1843. return $this->diffInSeconds($this->copy()->endOfDay()); 
  1844.  
  1845. /** 
  1846. * Get the difference in a human readable format in the current locale. 
  1847. * 
  1848. * When comparing a value in the past to default now: 
  1849. * 1 hour ago 
  1850. * 5 months ago 
  1851. * 
  1852. * When comparing a value in the future to default now: 
  1853. * 1 hour from now 
  1854. * 5 months from now 
  1855. * 
  1856. * When comparing a value in the past to another value: 
  1857. * 1 hour before 
  1858. * 5 months before 
  1859. * 
  1860. * When comparing a value in the future to another value: 
  1861. * 1 hour after 
  1862. * 5 months after 
  1863. * 
  1864. * @param Carbon|null $other 
  1865. * @param bool $absolute removes time difference modifiers ago, after, etc 
  1866. * 
  1867. * @return string 
  1868. */ 
  1869. public function diffForHumans(Carbon $other = null, $absolute = false) 
  1870. $isNow = $other === null; 
  1871.  
  1872. if ($isNow) { 
  1873. $other = static::now($this->tz); 
  1874.  
  1875. $diffInterval = $this->diff($other); 
  1876.  
  1877. switch (true) { 
  1878. case ($diffInterval->y > 0): 
  1879. $unit = 'year'; 
  1880. $count = $diffInterval->y; 
  1881. break; 
  1882.  
  1883. case ($diffInterval->m > 0): 
  1884. $unit = 'month'; 
  1885. $count = $diffInterval->m; 
  1886. break; 
  1887.  
  1888. case ($diffInterval->d > 0): 
  1889. $unit = 'day'; 
  1890. $count = $diffInterval->d; 
  1891. if ($count >= self::DAYS_PER_WEEK) { 
  1892. $unit = 'week'; 
  1893. $count = (int) ($count / self::DAYS_PER_WEEK); 
  1894. break; 
  1895.  
  1896. case ($diffInterval->h > 0): 
  1897. $unit = 'hour'; 
  1898. $count = $diffInterval->h; 
  1899. break; 
  1900.  
  1901. case ($diffInterval->i > 0): 
  1902. $unit = 'minute'; 
  1903. $count = $diffInterval->i; 
  1904. break; 
  1905.  
  1906. default: 
  1907. $count = $diffInterval->s; 
  1908. $unit = 'second'; 
  1909. break; 
  1910.  
  1911. if ($count === 0) { 
  1912. $count = 1; 
  1913.  
  1914. $time = static::translator()->transChoice($unit, $count, array(':count' => $count)); 
  1915.  
  1916. if ($absolute) { 
  1917. return $time; 
  1918.  
  1919. $isFuture = $diffInterval->invert === 1; 
  1920.  
  1921. $transId = $isNow ? ($isFuture ? 'from_now' : 'ago') : ($isFuture ? 'after' : 'before'); 
  1922.  
  1923. // Some langs have special pluralization for past and future tense. 
  1924. $tryKeyExists = $unit.'_'.$transId; 
  1925. if ($tryKeyExists !== static::translator()->transChoice($tryKeyExists, $count)) { 
  1926. $time = static::translator()->transChoice($tryKeyExists, $count, array(':count' => $count)); 
  1927.  
  1928. return static::translator()->trans($transId, array(':time' => $time)); 
  1929.  
  1930. /////////////////////////////////////////////////////////////////// 
  1931. //////////////////////////// MODIFIERS //////////////////////////// 
  1932. /////////////////////////////////////////////////////////////////// 
  1933.  
  1934. /** 
  1935. * Resets the time to 00:00:00 
  1936. * 
  1937. * @return static 
  1938. */ 
  1939. public function startOfDay() 
  1940. return $this->hour(0)->minute(0)->second(0); 
  1941.  
  1942. /** 
  1943. * Resets the time to 23:59:59 
  1944. * 
  1945. * @return static 
  1946. */ 
  1947. public function endOfDay() 
  1948. return $this->hour(23)->minute(59)->second(59); 
  1949.  
  1950. /** 
  1951. * Resets the date to the first day of the month and the time to 00:00:00 
  1952. * 
  1953. * @return static 
  1954. */ 
  1955. public function startOfMonth() 
  1956. return $this->startOfDay()->day(1); 
  1957.  
  1958. /** 
  1959. * Resets the date to end of the month and time to 23:59:59 
  1960. * 
  1961. * @return static 
  1962. */ 
  1963. public function endOfMonth() 
  1964. return $this->day($this->daysInMonth)->endOfDay(); 
  1965.  
  1966. /** 
  1967. * Resets the date to the first day of the year and the time to 00:00:00 
  1968. * 
  1969. * @return static 
  1970. */ 
  1971. public function startOfYear() 
  1972. return $this->month(1)->startOfMonth(); 
  1973.  
  1974. /** 
  1975. * Resets the date to end of the year and time to 23:59:59 
  1976. * 
  1977. * @return static 
  1978. */ 
  1979. public function endOfYear() 
  1980. return $this->month(static::MONTHS_PER_YEAR)->endOfMonth(); 
  1981.  
  1982. /** 
  1983. * Resets the date to the first day of the decade and the time to 00:00:00 
  1984. * 
  1985. * @return static 
  1986. */ 
  1987. public function startOfDecade() 
  1988. return $this->startOfYear()->year($this->year - $this->year % static::YEARS_PER_DECADE); 
  1989.  
  1990. /** 
  1991. * Resets the date to end of the decade and time to 23:59:59 
  1992. * 
  1993. * @return static 
  1994. */ 
  1995. public function endOfDecade() 
  1996. return $this->endOfYear()->year($this->year - $this->year % static::YEARS_PER_DECADE + static::YEARS_PER_DECADE - 1); 
  1997.  
  1998. /** 
  1999. * Resets the date to the first day of the century and the time to 00:00:00 
  2000. * 
  2001. * @return static 
  2002. */ 
  2003. public function startOfCentury() 
  2004. return $this->startOfYear()->year($this->year - $this->year % static::YEARS_PER_CENTURY); 
  2005.  
  2006. /** 
  2007. * Resets the date to end of the century and time to 23:59:59 
  2008. * 
  2009. * @return static 
  2010. */ 
  2011. public function endOfCentury() 
  2012. return $this->endOfYear()->year($this->year - $this->year % static::YEARS_PER_CENTURY + static::YEARS_PER_CENTURY - 1); 
  2013.  
  2014. /** 
  2015. * Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00 
  2016. * 
  2017. * @return static 
  2018. */ 
  2019. public function startOfWeek() 
  2020. if ($this->dayOfWeek !== static::$weekStartsAt) { 
  2021. $this->previous(static::$weekStartsAt); 
  2022.  
  2023. return $this->startOfDay(); 
  2024.  
  2025. /** 
  2026. * Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59 
  2027. * 
  2028. * @return static 
  2029. */ 
  2030. public function endOfWeek() 
  2031. if ($this->dayOfWeek !== static::$weekEndsAt) { 
  2032. $this->next(static::$weekEndsAt); 
  2033.  
  2034. return $this->endOfDay(); 
  2035.  
  2036. /** 
  2037. * Modify to the next occurrence of a given day of the week. 
  2038. * If no dayOfWeek is provided, modify to the next occurrence 
  2039. * of the current day of the week. Use the supplied consts 
  2040. * to indicate the desired dayOfWeek, ex. static::MONDAY. 
  2041. * 
  2042. * @param int|null $dayOfWeek 
  2043. * 
  2044. * @return static 
  2045. */ 
  2046. public function next($dayOfWeek = null) 
  2047. if ($dayOfWeek === null) { 
  2048. $dayOfWeek = $this->dayOfWeek; 
  2049.  
  2050. return $this->startOfDay()->modify('next '.static::$days[$dayOfWeek]); 
  2051.  
  2052. /** 
  2053. * Modify to the previous occurrence of a given day of the week. 
  2054. * If no dayOfWeek is provided, modify to the previous occurrence 
  2055. * of the current day of the week. Use the supplied consts 
  2056. * to indicate the desired dayOfWeek, ex. static::MONDAY. 
  2057. * 
  2058. * @param int|null $dayOfWeek 
  2059. * 
  2060. * @return static 
  2061. */ 
  2062. public function previous($dayOfWeek = null) 
  2063. if ($dayOfWeek === null) { 
  2064. $dayOfWeek = $this->dayOfWeek; 
  2065.  
  2066. return $this->startOfDay()->modify('last '.static::$days[$dayOfWeek]); 
  2067.  
  2068. /** 
  2069. * Modify to the first occurrence of a given day of the week 
  2070. * in the current month. If no dayOfWeek is provided, modify to the 
  2071. * first day of the current month. Use the supplied consts 
  2072. * to indicate the desired dayOfWeek, ex. static::MONDAY. 
  2073. * 
  2074. * @param int|null $dayOfWeek 
  2075. * 
  2076. * @return static 
  2077. */ 
  2078. public function firstOfMonth($dayOfWeek = null) 
  2079. $this->startOfDay(); 
  2080.  
  2081. if ($dayOfWeek === null) { 
  2082. return $this->day(1); 
  2083.  
  2084. return $this->modify('first '.static::$days[$dayOfWeek].' of '.$this->format('F').' '.$this->year); 
  2085.  
  2086. /** 
  2087. * Modify to the last occurrence of a given day of the week 
  2088. * in the current month. If no dayOfWeek is provided, modify to the 
  2089. * last day of the current month. Use the supplied consts 
  2090. * to indicate the desired dayOfWeek, ex. static::MONDAY. 
  2091. * 
  2092. * @param int|null $dayOfWeek 
  2093. * 
  2094. * @return static 
  2095. */ 
  2096. public function lastOfMonth($dayOfWeek = null) 
  2097. $this->startOfDay(); 
  2098.  
  2099. if ($dayOfWeek === null) { 
  2100. return $this->day($this->daysInMonth); 
  2101.  
  2102. return $this->modify('last '.static::$days[$dayOfWeek].' of '.$this->format('F').' '.$this->year); 
  2103.  
  2104. /** 
  2105. * Modify to the given occurrence of a given day of the week 
  2106. * in the current month. If the calculated occurrence is outside the scope 
  2107. * of the current month, then return false and no modifications are made. 
  2108. * Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY. 
  2109. * 
  2110. * @param int $nth 
  2111. * @param int $dayOfWeek 
  2112. * 
  2113. * @return mixed 
  2114. */ 
  2115. public function nthOfMonth($nth, $dayOfWeek) 
  2116. $dt = $this->copy()->firstOfMonth(); 
  2117. $check = $dt->format('Y-m'); 
  2118. $dt->modify('+'.$nth.' '.static::$days[$dayOfWeek]); 
  2119.  
  2120. return $dt->format('Y-m') === $check ? $this->modify($dt) : false; 
  2121.  
  2122. /** 
  2123. * Modify to the first occurrence of a given day of the week 
  2124. * in the current quarter. If no dayOfWeek is provided, modify to the 
  2125. * first day of the current quarter. Use the supplied consts 
  2126. * to indicate the desired dayOfWeek, ex. static::MONDAY. 
  2127. * 
  2128. * @param int|null $dayOfWeek 
  2129. * 
  2130. * @return static 
  2131. */ 
  2132. public function firstOfQuarter($dayOfWeek = null) 
  2133. return $this->day(1)->month($this->quarter * 3 - 2)->firstOfMonth($dayOfWeek); 
  2134.  
  2135. /** 
  2136. * Modify to the last occurrence of a given day of the week 
  2137. * in the current quarter. If no dayOfWeek is provided, modify to the 
  2138. * last day of the current quarter. Use the supplied consts 
  2139. * to indicate the desired dayOfWeek, ex. static::MONDAY. 
  2140. * 
  2141. * @param int|null $dayOfWeek 
  2142. * 
  2143. * @return static 
  2144. */ 
  2145. public function lastOfQuarter($dayOfWeek = null) 
  2146. return $this->day(1)->month($this->quarter * 3)->lastOfMonth($dayOfWeek); 
  2147.  
  2148. /** 
  2149. * Modify to the given occurrence of a given day of the week 
  2150. * in the current quarter. If the calculated occurrence is outside the scope 
  2151. * of the current quarter, then return false and no modifications are made. 
  2152. * Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY. 
  2153. * 
  2154. * @param int $nth 
  2155. * @param int $dayOfWeek 
  2156. * 
  2157. * @return mixed 
  2158. */ 
  2159. public function nthOfQuarter($nth, $dayOfWeek) 
  2160. $dt = $this->copy()->day(1)->month($this->quarter * 3); 
  2161. $lastMonth = $dt->month; 
  2162. $year = $dt->year; 
  2163. $dt->firstOfQuarter()->modify('+'.$nth.' '.static::$days[$dayOfWeek]); 
  2164.  
  2165. return ($lastMonth < $dt->month || $year !== $dt->year) ? false : $this->modify($dt); 
  2166.  
  2167. /** 
  2168. * Modify to the first occurrence of a given day of the week 
  2169. * in the current year. If no dayOfWeek is provided, modify to the 
  2170. * first day of the current year. Use the supplied consts 
  2171. * to indicate the desired dayOfWeek, ex. static::MONDAY. 
  2172. * 
  2173. * @param int|null $dayOfWeek 
  2174. * 
  2175. * @return static 
  2176. */ 
  2177. public function firstOfYear($dayOfWeek = null) 
  2178. return $this->month(1)->firstOfMonth($dayOfWeek); 
  2179.  
  2180. /** 
  2181. * Modify to the last occurrence of a given day of the week 
  2182. * in the current year. If no dayOfWeek is provided, modify to the 
  2183. * last day of the current year. Use the supplied consts 
  2184. * to indicate the desired dayOfWeek, ex. static::MONDAY. 
  2185. * 
  2186. * @param int|null $dayOfWeek 
  2187. * 
  2188. * @return static 
  2189. */ 
  2190. public function lastOfYear($dayOfWeek = null) 
  2191. return $this->month(static::MONTHS_PER_YEAR)->lastOfMonth($dayOfWeek); 
  2192.  
  2193. /** 
  2194. * Modify to the given occurrence of a given day of the week 
  2195. * in the current year. If the calculated occurrence is outside the scope 
  2196. * of the current year, then return false and no modifications are made. 
  2197. * Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY. 
  2198. * 
  2199. * @param int $nth 
  2200. * @param int $dayOfWeek 
  2201. * 
  2202. * @return mixed 
  2203. */ 
  2204. public function nthOfYear($nth, $dayOfWeek) 
  2205. $dt = $this->copy()->firstOfYear()->modify('+'.$nth.' '.static::$days[$dayOfWeek]); 
  2206.  
  2207. return $this->year === $dt->year ? $this->modify($dt) : false; 
  2208.  
  2209. /** 
  2210. * Modify the current instance to the average of a given instance (default now) and the current instance. 
  2211. * 
  2212. * @param Carbon|null $dt 
  2213. * 
  2214. * @return static 
  2215. */ 
  2216. public function average(Carbon $dt = null) 
  2217. $dt = $dt ?: static::now($this->tz); 
  2218.  
  2219. return $this->addSeconds((int) ($this->diffInSeconds($dt, false) / 2)); 
  2220.  
  2221. /** 
  2222. * Check if its the birthday. Compares the date/month values of the two dates. 
  2223. * 
  2224. * @param Carbon|null $dt The instance to compare with or null to use current day. 
  2225. * 
  2226. * @return bool 
  2227. */ 
  2228. public function isBirthday(Carbon $dt = null) 
  2229. $dt = $dt ?: static::now($this->tz); 
  2230.  
  2231. return $this->format('md') === $dt->format('md'); 
.