t $timestamp): static; /** * Set the instance's timezone from a string or object. */ public function setTimezone(DateTimeZone|string|int $timeZone): static; /** * @deprecated To avoid conflict between different third-party libraries, static setters should not be used. * You should rather let Carbon object being cast to string with DEFAULT_TO_STRING_FORMAT, and * use other method or custom format passed to format() method if you need to dump another string * format. * * Set the default format used when type juggling a Carbon instance to a string. * * @param string|Closure|null $format * * @return void */ public static function setToStringFormat(Closure|string|null $format): void; /** * Set the default translator instance to use. * * @param TranslatorInterface $translator * * @return void */ public static function setTranslator(TranslatorInterface $translator): void; /** * Set specified unit to new given value. * * @param string $unit year, month, day, hour, minute, second or microsecond * @param Month|int $value new value for given unit */ public function setUnit(string $unit, Month|int|float|null $value = null): static; /** * Set any unit to a new value without overflowing current other unit given. * * @param string $valueUnit unit name to modify * @param int $value new value for the input unit * @param string $overflowUnit unit name to not overflow */ public function setUnitNoOverflow(string $valueUnit, int $value, string $overflowUnit): static; /** * @deprecated To avoid conflict between different third-party libraries, static setters should not be used. * You should rather consider week-end is always saturday and sunday, and if you have some custom * week-end days to handle, give to those days an other name and create a macro for them: * * ``` * Carbon::macro('isDayOff', function ($date) { * return $date->isSunday() || $date->isMonday(); * }); * Carbon::macro('isNotDayOff', function ($date) { * return !$date->isDayOff(); * }); * if ($someDate->isDayOff()) ... * if ($someDate->isNotDayOff()) ... * // Add 5 not-off days * $count = 5; * while ($someDate->isDayOff() || ($count-- > 0)) { * $someDate->addDay(); * } * ``` * * Set weekend days */ public static function setWeekendDays(array $days): void; /** * Set specific options. * - strictMode: true|false|null * - monthOverflow: true|false|null * - yearOverflow: true|false|null * - humanDiffOptions: int|null * - toStringFormat: string|Closure|null * - toJsonFormat: string|Closure|null * - locale: string|null * - timezone: \DateTimeZone|string|int|null * - macros: array|null * - genericMacros: array|null * * @param array $settings * * @return $this|static */ public function settings(array $settings): static; /** * Set the instance's timezone from a string or object and add/subtract the offset difference. */ public function shiftTimezone(DateTimeZone|string $value): static; /** * Get the month overflow global behavior (can be overridden in specific instances). * * @return bool */ public static function shouldOverflowMonths(): bool; /** * Get the month overflow global behavior (can be overridden in specific instances). * * @return bool */ public static function shouldOverflowYears(): bool; /** * @alias diffForHumans * * Get the difference in a human readable format in the current locale from current instance to an other * instance given (or now if null given). */ public function since($other = null, $syntax = null, $short = false, $parts = 1, $options = null); /** * Returns standardized singular of a given singular/plural unit name (in English). */ public static function singularUnit(string $unit): string; public static function sleep(int|float $seconds): void; /** * Modify to start of current given unit. * * @example * ``` * echo Carbon::parse('2018-07-25 12:45:16.334455') * ->startOf(Unit::Month) * ->endOf(Unit::Week, Carbon::FRIDAY); * ``` */ public function startOf(Unit|string $unit, mixed ...$params): static; /** * Resets the date to the first day of the century and the time to 00:00:00 * * @example * ``` * echo Carbon::parse('2018-07-25 12:45:16')->startOfCentury(); * ``` * * @return static */ public function startOfCentury(); /** * Resets the time to 00:00:00 start of day * * @example * ``` * echo Carbon::parse('2018-07-25 12:45:16')->startOfDay(); * ``` * * @return static */ public function startOfDay(); /** * Resets the date to the first day of the decade and the time to 00:00:00 * * @example * ``` * echo Carbon::parse('2018-07-25 12:45:16')->startOfDecade(); * ``` * * @return static */ public function startOfDecade(); /** * Modify to start of current hour, minutes and seconds become 0 * * @example * ``` * echo Carbon::parse('2018-07-25 12:45:16')->startOfHour(); * ``` */ public function startOfHour(): static; /** * Resets the date to the first day of the millennium and the time to 00:00:00 * * @example * ``` * echo Carbon::parse('2018-07-25 12:45:16')->startOfMillennium(); * ``` * * @return static */ public function startOfMillennium(); /** * Modify to start of current millisecond, microseconds such as 12345 become 123000 * * @example * ``` * echo Carbon::parse('2018-07-25 12:45:16.334455') * ->startOfSecond() * ->format('H:i:s.u'); * ``` */ public function startOfMillisecond(): static; /** * Modify to start of current minute, seconds become 0 * * @example * ``` * echo Carbon::parse('2018-07-25 12:45:16')->startOfMinute(); * ``` */ public function startOfMinute(): static; /** * Resets the date to the first day of the month and the time to 00:00:00 * * @example * ``` * echo Carbon::parse('2018-07-25 12:45:16')->startOfMonth(); * ``` * * @return static */ public function startOfMonth(); /** * Resets the date to the first day of the quarter and the time to 00:00:00 * * @example * ``` * echo Carbon::parse('2018-07-25 12:45:16')->startOfQuarter(); * ``` * * @return static */ public function startOfQuarter(); /** * Modify to start of current second, microseconds become 0 * * @example * ``` * echo Carbon::parse('2018-07-25 12:45:16.334455') * ->startOfSecond() * ->format('H:i:s.u'); * ``` */ public function startOfSecond(): static; /** * Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00 * * @example * ``` * echo Carbon::parse('2018-07-25 12:45:16')->startOfWeek() . "\n"; * echo Carbon::parse('2018-07-25 12:45:16')->locale('ar')->startOfWeek() . "\n"; * echo Carbon::parse('2018-07-25 12:45:16')->startOfWeek(Carbon::SUNDAY) . "\n"; * ``` * * @param WeekDay|int|null $weekStartsAt optional start allow you to specify the day of week to use to start the week * * @return static */ public function startOfWeek(WeekDay|int|null $weekStartsAt = null): static; /** * Resets the date to the first day of the year and the time to 00:00:00 * * @example * ``` * echo Carbon::parse('2018-07-25 12:45:16')->startOfYear(); * ``` * * @return static */ public function startOfYear(); /** * Subtract given units or interval to the current instance. * * @example $date->sub('hour', 3) * @example $date->sub(15, 'days') * @example $date->sub(CarbonInterval::days(4)) * * @param Unit|int|string|DateInterval|Closure|CarbonConverterInterface $unit * @param Unit|int|float|string $value * @param bool|null $overflow * * @return static */ #[ReturnTypeWillChange] public function sub($unit, $value = 1, ?bool $overflow = null): static; /** * @deprecated Prefer to use add subUTCUnit() which more accurately defines what it's doing. * * Subtract seconds to the instance using timestamp. Positive $value travels * into the past while negative $value travels forward. * * @param string $unit * @param int $value * * @return static */ public function subRealUnit($unit, $value = 1): static; /** * Subtract seconds to the instance using timestamp. Positive $value travels * into the past while negative $value travels forward. * * @param string $unit * @param int $value * * @return static */ public function subUTCUnit($unit, $value = 1): static; /** * Subtract given units to the current instance. */ public function subUnit(Unit|string $unit, $value = 1, ?bool $overflow = null): static; /** * Subtract any unit to a new value without overflowing current other unit given. * * @param string $valueUnit unit name to modify * @param int $value amount to subtract to the input unit * @param string $overflowUnit unit name to not overflow */ public function subUnitNoOverflow(string $valueUnit, int $value, string $overflowUnit): static; /** * Subtract given units or interval to the current instance. * * @see sub() * * @param Unit|int|string|DateInterval $unit * @param Unit|int|float|string $value * @param bool|null $overflow * * @return static */ public function subtract($unit, $value = 1, ?bool $overflow = null): static; /** * Get the difference in a human-readable format in the current locale from current instance to another * instance given (or now if null given). * * @return string */ public function timespan($other = null, $timezone = null): string; /** * Set the instance's timestamp. * * Timestamp input can be given as int, float or a string containing one or more numbers. */ public function timestamp(string|int|float $timestamp): static; /** * @alias setTimezone */ public function timezone(DateTimeZone|string|int $value): static; /** * Get the difference in a human readable format in the current locale from an other * instance given (or now if null given) to current instance. * * When comparing a value in the past to default now: * 1 hour from now * 5 months from now * * When comparing a value in the future to default now: * 1 hour ago * 5 months ago * * When comparing a value in the past to another value: * 1 hour after * 5 months after * * When comparing a value in the future to another value: * 1 hour before * 5 months before * * @param Carbon|\DateTimeInterface|string|array|null $other if array passed, will be used as parameters array, see $syntax below; * if null passed, now will be used as comparison reference; * if any other type, it will be converted to date and used as reference. * @param int|array $syntax if array passed, parameters will be extracted from it, the array may contains: * - 'syntax' entry (see below) * - 'short' entry (see below) * - 'parts' entry (see below) * - 'options' entry (see below) * - 'join' entry determines how to join multiple parts of the string * ` - if $join is a string, it's used as a joiner glue * ` - if $join is a callable/closure, it get the list of string and should return a string * ` - if $join is an array, the first item will be the default glue, and the second item * ` will be used instead of the glue for the last item * ` - if $join is true, it will be guessed from the locale ('list' translation file entry) * ` - if $join is missing, a space will be used as glue * - 'other' entry (see above) * if int passed, it add modifiers: * Possible values: * - CarbonInterface::DIFF_ABSOLUTE no modifiers * - CarbonInterface::DIFF_RELATIVE_TO_NOW add ago/from now modifier * - CarbonInterface::DIFF_RELATIVE_TO_OTHER add before/after modifier * Default value: CarbonInterface::DIFF_ABSOLUTE * @param bool $short displays short format of time units * @param int $parts maximum number of parts to display (default value: 1: single unit) * @param int $options human diff options * * @return string */ public function to($other = null, $syntax = null, $short = false, $parts = 1, $options = null); /** * Get default array representation. * * @example * ``` * var_dump(Carbon::now()->toArray()); * ``` */ public function toArray(): array; /** * Format the instance as ATOM * * @example * ``` * echo Carbon::now()->toAtomString(); * ``` */ public function toAtomString(): string; /** * Format the instance as COOKIE * * @example * ``` * echo Carbon::now()->toCookieString(); * ``` */ public function toCookieString(): string; /** * @alias toDateTime * * Return native DateTime PHP object matching the current instance. * * @example * ``` * var_dump(Carbon::now()->toDate()); * ``` */ public function toDate(): DateTime; /** * Format the instance as date * * @example * ``` * echo Carbon::now()->toDateString(); * ``` */ public function toDateString(): string; /** * Return native DateTime PHP object matching the current instance. * * @example * ``` * var_dump(Carbon::now()->toDateTime()); * ``` */ public function toDateTime(): DateTime; /** * Return native toDateTimeImmutable PHP object matching the current instance. * * @example * ``` * var_dump(Carbon::now()->toDateTimeImmutable()); * ``` */ public function toDateTimeImmutable(): DateTimeImmutable; /** * Format the instance as date and time T-separated with no timezone * * @example * ``` * echo Carbon::now()->toDateTimeLocalString(); * echo "\n"; * echo Carbon::now()->toDateTimeLocalString('minute'); // You can specify precision among: minute, second, millisecond and microsecond * ``` */ public function toDateTimeLocalString(string $unitPrecision = 'second'): string; /** * Format the instance as date and time * * @example * ``` * echo Carbon::now()->toDateTimeString(); * ``` */ public function toDateTimeString(string $unitPrecision = 'second'): string; /** * Format the instance with day, date and time * * @example * ``` * echo Carbon::now()->toDayDateTimeString(); * ``` */ public function toDayDateTimeString(): string; /** * Format the instance as a readable date * * @example * ``` * echo Carbon::now()->toFormattedDateString(); * ``` */ public function toFormattedDateString(): string; /** * Format the instance with the day, and a readable date * * @example * ``` * echo Carbon::now()->toFormattedDayDateString(); * ``` */ public function toFormattedDayDateString(): string; /** * Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z, if $keepOffset truthy, offset will be kept: * 1977-04-22T01:00:00-05:00). * * @example * ``` * echo Carbon::now('America/Toronto')->toISOString() . "\n"; * echo Carbon::now('America/Toronto')->toISOString(true) . "\n"; * ``` * * @param bool $keepOffset Pass true to keep the date offset. Else forced to UTC. */ public function toISOString(bool $keepOffset = false): ?string; /** * Return a immutable copy of the instance. * * @return CarbonImmutable */ public function toImmutable(); /** * Format the instance as ISO8601 * * @example * ``` * echo Carbon::now()->toIso8601String(); * ``` */ public function toIso8601String(): string; /** * Convert the instance to UTC and return as Zulu ISO8601 * * @example * ``` * echo Carbon::now()->toIso8601ZuluString(); * ``` */ public function toIso8601ZuluString(string $unitPrecision = 'second'): string; /** * Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z) with UTC timezone. * * @example * ``` * echo Carbon::now('America/Toronto')->toJSON(); * ``` */ public function toJSON(): ?string; /** * Return a mutable copy of the instance. * * @return Carbon */ public function toMutable(); /** * Get the difference in a human readable format in the current locale from an other * instance given to now * * @param int|array $syntax if array passed, parameters will be extracted from it, the array may contains: * - 'syntax' entry (see below) * - 'short' entry (see below) * - 'parts' entry (see below) * - 'options' entry (see below) * - 'join' entry determines how to join multiple parts of the string * ` - if $join is a string, it's used as a joiner glue * ` - if $join is a callable/closure, it get the list of string and should return a string * ` - if $join is an array, the first item will be the default glue, and the second item * ` will be used instead of the glue for the last item * ` - if $join is true, it will be guessed from the locale ('list' translation file entry) * ` - if $join is missing, a space will be used as glue * if int passed, it add modifiers: * Possible values: * - CarbonInterface::DIFF_ABSOLUTE no modifiers * - CarbonInterface::DIFF_RELATIVE_TO_NOW add ago/from now modifier * - CarbonInterface::DIFF_RELATIVE_TO_OTHER add before/after modifier * Default value: CarbonInterface::DIFF_ABSOLUTE * @param bool $short displays short format of time units * @param int $parts maximum number of parts to display (default value: 1: single part) * @param int $options human diff options * * @return string */ public function toNow($syntax = null, $short = false, $parts = 1, $options = null); /** * Get default object representation. * * @example * ``` * var_dump(Carbon::now()->toObject()); * ``` */ public function toObject(): object; /** * Create a iterable CarbonPeriod object from current date to a given end date (and optional interval). * * @param \DateTimeInterface|Carbon|CarbonImmutable|int|null $end period end date or recurrences count if int * @param int|\DateInterval|string|null $interval period default interval or number of the given $unit * @param string|null $unit if specified, $interval must be an integer */ public function toPeriod($end = null, $interval = null, $unit = null): CarbonPeriod; /** * Format the instance as RFC1036 * * @example * ``` * echo Carbon::now()->toRfc1036String(); * ``` */ public function toRfc1036String(): string; /** * Format the instance as RFC1123 * * @example * ``` * echo Carbon::now()->toRfc1123String(); * ``` */ public function toRfc1123String(): string; /** * Format the instance as RFC2822 * * @example * ``` * echo Carbon::now()->toRfc2822String(); * ``` */ public function toRfc2822String(): string; /** * Format the instance as RFC3339. * * @example * ``` * echo Carbon::now()->toRfc3339String() . "\n"; * echo Carbon::now()->toRfc3339String(true) . "\n"; * ``` */ public function toRfc3339String(bool $extended = false): string; /** * Format the instance as RFC7231 * * @example * ``` * echo Carbon::now()->toRfc7231String(); * ``` */ public function toRfc7231String(): string; /** * Format the instance as RFC822 * * @example * ``` * echo Carbon::now()->toRfc822String(); * ``` */ public function toRfc822String(): string; /** * Format the instance as RFC850 * * @example * ``` * echo Carbon::now()->toRfc850String(); * ``` */ public function toRfc850String(): string; /** * Format the instance as RSS * * @example * ``` * echo Carbon::now()->toRssString(); * ``` */ public function toRssString(): string; /** * Returns english human-readable complete date string. * * @example * ``` * echo Carbon::now()->toString(); * ``` */ public function toString(): string; /** * Format the instance as time * * @example * ``` * echo Carbon::now()->toTimeString(); * ``` */ public function toTimeString(string $unitPrecision = 'second'): string; /** * Format the instance as W3C * * @example * ``` * echo Carbon::now()->toW3cString(); * ``` */ public function toW3cString(): string; /** * Create a Carbon instance for today. */ public static function today(DateTimeZone|string|int|null $timezone = null): static; /** * Create a Carbon instance for tomorrow. */ public static function tomorrow(DateTimeZone|string|int|null $timezone = null): static; /** * Translate using translation string or callback available. * * @param string $key key to find * @param array $parameters replacement parameters * @param string|int|float|null $number number if plural * @param TranslatorInterface|null $translator an optional translator to use * @param bool $altNumbers pass true to use alternative numbers * * @return string */ public function translate(string $key, array $parameters = [], string|int|float|null $number = null, ?TranslatorInterface $translator = null, bool $altNumbers = false): string; /** * Returns the alternative number for a given integer if available in the current locale. * * @param int $number * * @return string */ public function translateNumber(int $number): string; /** * Translate a time string from a locale to an other. * * @param string $timeString date/time/duration string to translate (may also contain English) * @param string|null $from input locale of the $timeString parameter (`Carbon::getLocale()` by default) * @param string|null $to output locale of the result returned (`"en"` by default) * @param int $mode specify what to translate with options: * - self::TRANSLATE_ALL (default) * - CarbonInterface::TRANSLATE_MONTHS * - CarbonInterface::TRANSLATE_DAYS * - CarbonInterface::TRANSLATE_UNITS * - CarbonInterface::TRANSLATE_MERIDIEM * You can use pipe to group: CarbonInterface::TRANSLATE_MONTHS | CarbonInterface::TRANSLATE_DAYS * * @return string */ public static function translateTimeString(string $timeString, ?string $from = null, ?string $to = null, int $mode = self::TRANSLATE_ALL): string; /** * Translate a time string from the current locale (`$date->locale()`) to an other. * * @param string $timeString time string to translate * @param string|null $to output locale of the result returned ("en" by default) * * @return string */ public function translateTimeStringTo(string $timeString, ?string $to = null): string; /** * Translate using translation string or callback available. * * @param TranslatorInterface $translator an optional translator to use * @param string $key key to find * @param array $parameters replacement parameters * @param int|float|null $number number if plural * * @return string */ public static function translateWith(TranslatorInterface $translator, string $key, array $parameters = [], $number = null): string; /** * Format as ->format() do (using date replacements patterns from https://php.net/manual/en/function.date.php) * but translate words whenever possible (months, day names, etc.) using the current locale. */ public function translatedFormat(string $format): string; /** * Set the timezone or returns the timezone name if no arguments passed. */ public function tz(DateTimeZone|string|int|null $value = null): static|string; /** * @alias getTimestamp * * Returns the UNIX timestamp for the current date. * * @return int */ public function unix(): int; /** * @alias to * * Get the difference in a human readable format in the current locale from an other * instance given (or now if null given) to current instance. * * @param Carbon|\DateTimeInterface|string|array|null $other if array passed, will be used as parameters array, see $syntax below; * if null passed, now will be used as comparison reference; * if any other type, it will be converted to date and used as reference. * @param int|array $syntax if array passed, parameters will be extracted from it, the array may contains: * - 'syntax' entry (see below) * - 'short' entry (see below) * - 'parts' entry (see below) * - 'options' entry (see below) * - 'join' entry determines how to join multiple parts of the string * ` - if $join is a string, it's used as a joiner glue * ` - if $join is a callable/closure, it get the list of string and should return a string * ` - if $join is an array, the first item will be the default glue, and the second item * ` will be used instead of the glue for the last item * ` - if $join is true, it will be guessed from the locale ('list' translation file entry) * ` - if $join is missing, a space will be used as glue * - 'other' entry (see above) * if int passed, it add modifiers: * Possible values: * - CarbonInterface::DIFF_ABSOLUTE no modifiers * - CarbonInterface::DIFF_RELATIVE_TO_NOW add ago/from now modifier * - CarbonInterface::DIFF_RELATIVE_TO_OTHER add before/after modifier * Default value: CarbonInterface::DIFF_ABSOLUTE * @param bool $short displays short format of time units * @param int $parts maximum number of parts to display (default value: 1: single unit) * @param int $options human diff options * * @return string */ public function until($other = null, $syntax = null, $short = false, $parts = 1, $options = null); /** * @deprecated To avoid conflict between different third-party libraries, static setters should not be used. * You should rather use the ->settings() method. * Or you can use method variants: addMonthsWithOverflow/addMonthsNoOverflow, same variants * are available for quarters, years, decade, centuries, millennia (singular and plural forms). * @see settings * * Indicates if months should be calculated with overflow. * * @param bool $monthsOverflow * * @return void */ public static function useMonthsOverflow(bool $monthsOverflow = true): void; /** * @deprecated To avoid conflict between different third-party libraries, static setters should not be used. * You should rather use the ->settings() method. * @see settings * * Enable the strict mode (or disable with passing false). * * @param bool $strictModeEnabled */ public static function useStrictMode(bool $strictModeEnabled = true): void; /** * @deprecated To avoid conflict between different third-party libraries, static setters should not be used. * You should rather use the ->settings() method. * Or you can use method variants: addYearsWithOverflow/addYearsNoOverflow, same variants * are available for quarters, years, decade, centuries, millennia (singular and plural forms). * @see settings * * Indicates if years should be calculated with overflow. * * @param bool $yearsOverflow * * @return void */ public static function useYearsOverflow(bool $yearsOverflow = true): void; /** * Set the instance's timezone to UTC. */ public function utc(): static; /** * Returns the minutes offset to UTC if no arguments passed, else set the timezone with given minutes shift passed. */ public function utcOffset(?int $minuteOffset = null): static|int; /** * Returns the milliseconds timestamps used amongst other by Date javascript objects. * * @return float */ public function valueOf(): float; /** * Get/set the week number using given first day of week and first * day of year included in the first week. Or use US format if no settings * given (Sunday / Jan 6). * * @param int|null $week * @param int|null $dayOfWeek * @param int|null $dayOfYear * * @return int|static */ public function week($week = null, $dayOfWeek = null, $dayOfYear = null); /** * Set/get the week number of year using given first day of week and first * day of year included in the first week. Or use US format if no settings * given (Sunday / Jan 6). * * @param int|null $year if null, act as a getter, if not null, set the year and return current instance. * @param int|null $dayOfWeek first date of week from 0 (Sunday) to 6 (Saturday) * @param int|null $dayOfYear first day of year included in the week #1 * * @return int|static */ public function weekYear($year = null, $dayOfWeek = null, $dayOfYear = null); /** * Get/set the weekday from 0 (Sunday) to 6 (Saturday). * * @param WeekDay|int|null $value new value for weekday if using as setter. */ public function weekday(WeekDay|int|null $value = null): static|int; /** * Get the number of weeks of the current week-year using given first day of week and first * day of year included in the first week. Or use US format if no settings * given (Sunday / Jan 6). * * @param int|null $dayOfWeek first date of week from 0 (Sunday) to 6 (Saturday) * @param int|null $dayOfYear first day of year included in the week #1 * * @return int */ public function weeksInYear($dayOfWeek = null, $dayOfYear = null); /** * Temporarily sets a static date to be used within the callback. * Using setTestNow to set the date, executing the callback, then * clearing the test instance. * * /!\ Use this method for unit tests only. * * @template T * * @param DateTimeInterface|Closure|static|string|false|null $testNow real or mock Carbon instance * @param Closure(): T $callback * * @return T */ public static function withTestNow(mixed $testNow, callable $callback): mixed; /** * Create a Carbon instance for yesterday. */ public static function yesterday(DateTimeZone|string|int|null $timezone = null): static; // }