Pionia Core

FactoryImmutable extends Factory
in package
implements ClockInterface

A factory to generate CarbonImmutable instances with common settings.

<autodoc generated by composer phpdoc>

Table of Contents

Interfaces

ClockInterface

Properties

$className  : string
$regexFormatModifiers  : array<string|int, mixed>
Format modifiers (such as available in createFromFormat) regex patterns.
$regexFormats  : array<string, string>
Format regex patterns.
$settings  : array<string|int, mixed>
$testDefaultTimezone  : string|null
The timezone to restore to when clearing the time mock.
$testNow  : Closure|CarbonInterface|null
A test Carbon instance to be returned when now instances are created.
$translator  : TranslatorInterface
Default translator.
$useTimezoneFromTestNow  : bool
Is true when test-now is generated by a closure and timezone should be taken on the fly from it.
$weekendDays  : array<string|int, mixed>
Days of weekend.
$currentClock  : WrapperClock|null
$defaultInstance  : self|null

Methods

__call()  : mixed
__construct()  : mixed
canBeCreatedFromFormat()  : bool
canBeCreatedFromFormat()  : bool
className()  : self|string
createFromDate()  : CarbonImmutable
createFromDate()  : Carbon
createFromTime()  : CarbonImmutable
createFromTime()  : Carbon
createFromTimestamp()  : CarbonImmutable
createFromTimestamp()  : Carbon
createFromTimestampMs()  : CarbonImmutable
createFromTimestampMs()  : Carbon
createFromTimestampMsUTC()  : CarbonImmutable
createFromTimestampMsUTC()  : Carbon
createFromTimestampUTC()  : CarbonImmutable
createFromTimestampUTC()  : Carbon
createFromTimeString()  : CarbonImmutable
createFromTimeString()  : Carbon
createMidnightDate()  : CarbonImmutable
createMidnightDate()  : Carbon
createStrict()  : CarbonImmutable
createStrict()  : Carbon
disableHumanDiffOption()  : void
enableHumanDiffOption()  : void
executeWithLocale()  : mixed
executeWithLocale()  : mixed
fromSerialized()  : CarbonImmutable
fromSerialized()  : Carbon
genericMacro()  : void
Register a custom macro.
getAvailableLocales()  : array<string|int, mixed>
getAvailableLocales()  : array<string|int, mixed>
getAvailableLocalesInfo()  : array<string|int, Language>
getAvailableLocalesInfo()  : array<string|int, Language>
getClassName()  : string
getDays()  : array<string|int, mixed>
getDays()  : array<string|int, mixed>
getFormatsToIsoReplacements()  : array<string|int, mixed>
getFormatsToIsoReplacements()  : array<string|int, mixed>
getHumanDiffOptions()  : int
getIsoUnits()  : array<string|int, mixed>
getIsoUnits()  : array<string|int, mixed>
getLastErrors()  : array<string|int, mixed>|false
getLastErrors()  : array<string|int, mixed>|false
getLocale()  : string
getLocale()  : string
getMacro()  : callable|null
Get the raw callable macro registered globally for a given name.
getMidDayAt()  : int
getMidDayAt()  : int
getSettings()  : array<string|int, mixed>
getTestNow()  : Closure|CarbonInterface|null
Get the Carbon instance (real or mock) to be returned when a "now" instance is created.
getTimeFormatByPrecision()  : string
getTimeFormatByPrecision()  : string
getTranslationMessageWith()  : string|Closure|null
getTranslationMessageWith()  : string|Closure|null
getTranslator()  : TranslatorInterface
Initialize the default translator instance if necessary.
getWeekendDays()  : array<string|int, mixed>
Get weekend days
getWeekEndsAt()  : int
getWeekEndsAt()  : int
getWeekStartsAt()  : int
getWeekStartsAt()  : int
handleTestNowClosure()  : CarbonInterface|null
hasFormat()  : bool
Checks if the (date)time string is in a given format.
hasFormatWithModifiers()  : bool
Checks if the (date)time string is in a given format.
hasMacro()  : bool
Checks if macro is registered globally.
hasRelativeKeywords()  : bool
hasRelativeKeywords()  : bool
hasTestNow()  : bool
Determine if there is a valid test instance set. A valid test instance is anything that is not null.
instance()  : CarbonImmutable
instance()  : Carbon
isImmutable()  : bool
isImmutable()  : bool
isModifiableUnit()  : bool
isModifiableUnit()  : bool
isMutable()  : bool
isMutable()  : bool
isStrictModeEnabled()  : bool
Returns true if the strict mode is globally in use, false else.
localeHasDiffOneDayWords()  : bool
localeHasDiffOneDayWords()  : bool
localeHasDiffSyntax()  : bool
localeHasDiffSyntax()  : bool
localeHasDiffTwoDayWords()  : bool
localeHasDiffTwoDayWords()  : bool
localeHasPeriodSyntax()  : bool
localeHasPeriodSyntax()  : bool
localeHasShortUnits()  : bool
localeHasShortUnits()  : bool
macro()  : void
Register a custom macro.
mergeSettings()  : self
mixin()  : void
mixin()  : void
now()  : Carbon
now()  : CarbonImmutable
Get a Carbon instance for the current date and time.
parse()  : CarbonImmutable
parse()  : Carbon
parseFromLocale()  : CarbonImmutable
parseFromLocale()  : Carbon
pluralUnit()  : string
pluralUnit()  : string
rawParse()  : CarbonImmutable
rawParse()  : Carbon
resetMacros()  : void
Remove all macros and generic macros.
resetMonthsOverflow()  : void
Reset the month overflow behavior.
resetToStringFormat()  : void
Reset the format used to the default when type juggling a Carbon instance to a string
resetYearsOverflow()  : void
Reset the month overflow behavior.
serializeUsing()  : void
JSON serialize all Carbon instances using the given callback.
setClassName()  : self
setFallbackLocale()  : void
setFallbackLocale()  : void
setHumanDiffOptions()  : void
setLocale()  : void
setLocale()  : void
setMidDayAt()  : void
setMidDayAt()  : void
setSettings()  : self
setTestNow()  : void
Set a Carbon instance (real or mock) to be returned when a "now" instance is created. The provided instance will be returned specifically under the following conditions: - A call to the static now() method, ex. Carbon::now() - When a null (or blank string) is passed to the constructor or parse(), ex. new Carbon(null) - When the string "now" is passed to the constructor or parse(), ex. new Carbon('now') - When a string containing the desired time is passed to Carbon::parse().
setTestNowAndTimezone()  : void
Set a Carbon instance (real or mock) to be returned when a "now" instance is created. The provided instance will be returned specifically under the following conditions: - A call to the static now() method, ex. Carbon::now() - When a null (or blank string) is passed to the constructor or parse(), ex. new Carbon(null) - When the string "now" is passed to the constructor or parse(), ex. new Carbon('now') - When a string containing the desired time is passed to Carbon::parse().
settings()  : self|array<string|int, mixed>
setToStringFormat()  : void
Set the default format used when type juggling a Carbon instance to a string.
setTranslator()  : void
Set the default translator instance to use.
setWeekendDays()  : void
Set weekend days
shouldOverflowMonths()  : bool
Get the month overflow global behavior (can be overridden in specific instances).
shouldOverflowYears()  : bool
Get the month overflow global behavior (can be overridden in specific instances).
singularUnit()  : string
singularUnit()  : string
sleep()  : void
sleep()  : void
today()  : CarbonImmutable
today()  : Carbon
tomorrow()  : CarbonImmutable
tomorrow()  : Carbon
translateTimeString()  : string
translateTimeString()  : string
translateWith()  : string
translateWith()  : string
useMonthsOverflow()  : void
Indicates if months should be calculated with overflow.
useStrictMode()  : void
Enable the strict mode (or disable with passing false).
useYearsOverflow()  : void
Indicates if years should be calculated with overflow.
withTestNow()  : T
Temporarily sets a static date to be used within the callback.
withTimeZone()  : static
yesterday()  : CarbonImmutable
yesterday()  : Carbon
getMockedTestNow()  : CarbonInterface|null
Get the mocked date passed in setTestNow() and if it's a Closure, execute it.
matchFormatPattern()  : bool
Checks if the (date)time string is in a given format with given list of pattern replacements.
setDefaultTimezone()  : void

Properties

$className

protected string $className = \Carbon\CarbonImmutable::class

$regexFormatModifiers

Format modifiers (such as available in createFromFormat) regex patterns.

protected array<string|int, mixed> $regexFormatModifiers = ['*' => '.+', ' ' => '[ ]', '#' => '[;:\\/.,()-]', '?' => '([^a]|[a])', '!' => '', '|' => '', '+' => '']

$regexFormats

Format regex patterns.

protected array<string, string> $regexFormats = [ 'd' => '(3[01]|[12][0-9]|0[1-9])', 'D' => '(Sun|Mon|Tue|Wed|Thu|Fri|Sat)', 'j' => '([123][0-9]|[1-9])', 'l' => '([a-zA-Z]{2,})', 'N' => '([1-7])', 'S' => '(st|nd|rd|th)', 'w' => '([0-6])', 'z' => '(36[0-5]|3[0-5][0-9]|[12][0-9]{2}|[1-9]?[0-9])', 'W' => '(5[012]|[1-4][0-9]|0?[1-9])', 'F' => '([a-zA-Z]{2,})', 'm' => '(1[012]|0[1-9])', 'M' => '([a-zA-Z]{3})', 'n' => '(1[012]|[1-9])', 't' => '(2[89]|3[01])', 'L' => '(0|1)', 'o' => '([1-9][0-9]{0,4})', 'Y' => '([1-9]?[0-9]{4})', 'y' => '([0-9]{2})', 'a' => '(am|pm)', 'A' => '(AM|PM)', 'B' => '([0-9]{3})', 'g' => '(1[012]|[1-9])', 'G' => '(2[0-3]|1?[0-9])', 'h' => '(1[012]|0[1-9])', 'H' => '(2[0-3]|[01][0-9])', 'i' => '([0-5][0-9])', 's' => '([0-5][0-9])', 'u' => '([0-9]{1,6})', 'v' => '([0-9]{1,3})', 'e' => '([a-zA-Z]{1,5})|([a-zA-Z]*\\/[a-zA-Z]*)', 'I' => '(0|1)', 'O' => '([+-](1[0123]|0[0-9])[0134][05])', 'P' => '([+-](1[0123]|0[0-9]):[0134][05])', 'p' => '(Z|[+-](1[0123]|0[0-9]):[0134][05])', 'T' => '([a-zA-Z]{1,5})', 'Z' => '(-?[1-5]?[0-9]{1,4})', 'U' => '([0-9]*)', // The formats below are combinations of the above formats. 'c' => '(([1-9]?[0-9]{4})-(1[012]|0[1-9])-(3[01]|[12][0-9]|0[1-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])[+-](1[012]|0[0-9]):([0134][05]))', // Y-m-dTH:i:sP 'r' => '(([a-zA-Z]{3}), ([123][0-9]|0[1-9]) ([a-zA-Z]{3}) ([1-9]?[0-9]{4}) (2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9]) [+-](1[012]|0[0-9])([0134][05]))', ]

$settings

protected array<string|int, mixed> $settings = []

$testDefaultTimezone

The timezone to restore to when clearing the time mock.

protected string|null $testDefaultTimezone = null

$testNow

A test Carbon instance to be returned when now instances are created.

protected Closure|CarbonInterface|null $testNow = null

$translator

Default translator.

protected TranslatorInterface $translator

$useTimezoneFromTestNow

Is true when test-now is generated by a closure and timezone should be taken on the fly from it.

protected bool $useTimezoneFromTestNow = false

$weekendDays

Days of weekend.

protected array<string|int, mixed> $weekendDays = [\Carbon\CarbonInterface::SATURDAY, \Carbon\CarbonInterface::SUNDAY]

Methods

__call()

public __call(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
$name : string
$arguments : array<string|int, mixed>

__construct()

public __construct([array<string|int, mixed> $settings = [] ][, string|null $className = null ]) : mixed
Parameters
$settings : array<string|int, mixed> = []
$className : string|null = null

canBeCreatedFromFormat()

public canBeCreatedFromFormat(string|null $date, string $format) : bool

Checks if the (date)time string is in a given format and valid to create a new instance.

Parameters
$date : string|null
$format : string
Return values
bool

canBeCreatedFromFormat()

public canBeCreatedFromFormat(string|null $date, string $format) : bool

Checks if the (date)time string is in a given format and valid to create a new instance.

Parameters
$date : string|null
$format : string
Return values
bool

className()

public className([string|null $className = null ]) : self|string
Parameters
$className : string|null = null
Return values
self|string

createFromDate()

public createFromDate(mixed $year, mixed $month, mixed $day, mixed $timezone) : CarbonImmutable

Create a Carbon instance from just a date. The time portion is set to now.

Parameters
$year : mixed
$month : mixed
$day : mixed
$timezone : mixed
Return values
CarbonImmutable

createFromDate()

public createFromDate(mixed $year, mixed $month, mixed $day, mixed $timezone) : Carbon

Create a Carbon instance from just a date. The time portion is set to now.

Parameters
$year : mixed
$month : mixed
$day : mixed
$timezone : mixed
Return values
Carbon

createFromTime()

public createFromTime(mixed $hour, mixed $minute, mixed $second, mixed $timezone) : CarbonImmutable

Create a Carbon instance from just a time. The date portion is set to today.

Parameters
$hour : mixed
$minute : mixed
$second : mixed
$timezone : mixed
Return values
CarbonImmutable

createFromTime()

public createFromTime(mixed $hour, mixed $minute, mixed $second, mixed $timezone) : Carbon

Create a Carbon instance from just a time. The date portion is set to today.

Parameters
$hour : mixed
$minute : mixed
$second : mixed
$timezone : mixed
Return values
Carbon

createFromTimestamp()

public createFromTimestamp(string|int|float $timestamp, DateTimeZone|string|int|null $timezone = null) : CarbonImmutable

Create a Carbon instance from a timestamp and set the timezone (UTC by default). Timestamp input can be given as int, float or a string containing one or more numbers.

Parameters
$timestamp : string|int|float
$timezone = null : DateTimeZone|string|int|null
Return values
CarbonImmutable

createFromTimestamp()

public createFromTimestamp(string|int|float $timestamp, DateTimeZone|string|int|null $timezone = null) : Carbon

Create a Carbon instance from a timestamp and set the timezone (UTC by default). Timestamp input can be given as int, float or a string containing one or more numbers.

Parameters
$timestamp : string|int|float
$timezone = null : DateTimeZone|string|int|null
Return values
Carbon

createFromTimestampMs()

public createFromTimestampMs(string|int|float $timestamp, DateTimeZone|string|int|null $timezone = null) : CarbonImmutable

Create a Carbon instance from a timestamp in milliseconds. Timestamp input can be given as int, float or a string containing one or more numbers.

Parameters
$timestamp : string|int|float
$timezone = null : DateTimeZone|string|int|null
Return values
CarbonImmutable

createFromTimestampMs()

public createFromTimestampMs(string|int|float $timestamp, DateTimeZone|string|int|null $timezone = null) : Carbon

Create a Carbon instance from a timestamp in milliseconds. Timestamp input can be given as int, float or a string containing one or more numbers.

Parameters
$timestamp : string|int|float
$timezone = null : DateTimeZone|string|int|null
Return values
Carbon

createFromTimestampMsUTC()

public createFromTimestampMsUTC(mixed $timestamp) : CarbonImmutable

Create a Carbon instance from a timestamp in milliseconds. Timestamp input can be given as int, float or a string containing one or more numbers.

Parameters
$timestamp : mixed
Return values
CarbonImmutable

createFromTimestampMsUTC()

public createFromTimestampMsUTC(mixed $timestamp) : Carbon

Create a Carbon instance from a timestamp in milliseconds. Timestamp input can be given as int, float or a string containing one or more numbers.

Parameters
$timestamp : mixed
Return values
Carbon

createFromTimestampUTC()

public createFromTimestampUTC(string|int|float $timestamp) : CarbonImmutable

Create a Carbon instance from a timestamp keeping the timezone to UTC. Timestamp input can be given as int, float or a string containing one or more numbers.

Parameters
$timestamp : string|int|float
Return values
CarbonImmutable

createFromTimestampUTC()

public createFromTimestampUTC(string|int|float $timestamp) : Carbon

Create a Carbon instance from a timestamp keeping the timezone to UTC. Timestamp input can be given as int, float or a string containing one or more numbers.

Parameters
$timestamp : string|int|float
Return values
Carbon

createFromTimeString()

public createFromTimeString(string $time, DateTimeZone|string|int|null $timezone = null) : CarbonImmutable

Create a Carbon instance from a time string. The date portion is set to today.

Parameters
$time : string
$timezone = null : DateTimeZone|string|int|null
Return values
CarbonImmutable

createFromTimeString()

public createFromTimeString(string $time, DateTimeZone|string|int|null $timezone = null) : Carbon

Create a Carbon instance from a time string. The date portion is set to today.

Parameters
$time : string
$timezone = null : DateTimeZone|string|int|null
Return values
Carbon

createMidnightDate()

public createMidnightDate(mixed $year, mixed $month, mixed $day, mixed $timezone) : CarbonImmutable

Create a Carbon instance from just a date. The time portion is set to midnight.

Parameters
$year : mixed
$month : mixed
$day : mixed
$timezone : mixed
Return values
CarbonImmutable

createMidnightDate()

public createMidnightDate(mixed $year, mixed $month, mixed $day, mixed $timezone) : Carbon

Create a Carbon instance from just a date. The time portion is set to midnight.

Parameters
$year : mixed
$month : mixed
$day : mixed
$timezone : mixed
Return values
Carbon

createStrict()

public createStrict(int|null $year = 0, int|null $month = 1, int|null $day = 1, int|null $hour = 0, int|null $minute = 0, int|null $second = 0, mixed $timezone) : CarbonImmutable

Create a new Carbon instance from a specific date and time using strict validation.

Parameters
$year = 0 : int|null
$month = 1 : int|null
$day = 1 : int|null
$hour = 0 : int|null
$minute = 0 : int|null
$second = 0 : int|null
$timezone : mixed
Return values
CarbonImmutable

createStrict()

public createStrict(int|null $year = 0, int|null $month = 1, int|null $day = 1, int|null $hour = 0, int|null $minute = 0, int|null $second = 0, mixed $timezone) : Carbon

Create a new Carbon instance from a specific date and time using strict validation.

Parameters
$year = 0 : int|null
$month = 1 : int|null
$day = 1 : int|null
$hour = 0 : int|null
$minute = 0 : int|null
$second = 0 : int|null
$timezone : mixed
Return values
Carbon

disableHumanDiffOption()

public disableHumanDiffOption(int $humanDiffOption) : void
Parameters
$humanDiffOption : int

enableHumanDiffOption()

public enableHumanDiffOption(mixed $humanDiffOption) : void
Parameters
$humanDiffOption : mixed

executeWithLocale()

public executeWithLocale(string $locale, callable $func) : mixed

Set the current locale to the given, execute the passed function, reset the locale to previous one, then return the result of the closure (or null if the closure was void).

Parameters
$locale : string
$func : callable

executeWithLocale()

public executeWithLocale(string $locale, callable $func) : mixed

Set the current locale to the given, execute the passed function, reset the locale to previous one, then return the result of the closure (or null if the closure was void).

Parameters
$locale : string
$func : callable

fromSerialized()

public fromSerialized(mixed $value) : Carbon

Create an instance from a serialized string.

Parameters
$value : mixed
Return values
Carbon

genericMacro()

Register a custom macro.

public genericMacro(callable $macro[, int $priority = 0 ]) : void
Parameters
$macro : callable
$priority : int = 0

marco with higher priority is tried first

getAvailableLocales()

public getAvailableLocales() : array<string|int, mixed>

Returns the list of internally available locales and already loaded custom locales. (It will ignore custom translator dynamic loading.)

Return values
array<string|int, mixed>

getAvailableLocales()

public getAvailableLocales() : array<string|int, mixed>

Returns the list of internally available locales and already loaded custom locales. (It will ignore custom translator dynamic loading.)

Return values
array<string|int, mixed>

getAvailableLocalesInfo()

public getAvailableLocalesInfo() : array<string|int, Language>

Returns list of Language object for each available locale. This object allow you to get the ISO name, native name, region and variant of the locale.

Return values
array<string|int, Language>

getAvailableLocalesInfo()

public getAvailableLocalesInfo() : array<string|int, Language>

Returns list of Language object for each available locale. This object allow you to get the ISO name, native name, region and variant of the locale.

Return values
array<string|int, Language>

getClassName()

public getClassName() : string
Return values
string

getDays()

public getDays() : array<string|int, mixed>

Get the days of the week.

Return values
array<string|int, mixed>

getDays()

public getDays() : array<string|int, mixed>

Get the days of the week.

Return values
array<string|int, mixed>

getFormatsToIsoReplacements()

public getFormatsToIsoReplacements() : array<string|int, mixed>

List of replacements from date() format to isoFormat().

Return values
array<string|int, mixed>

getFormatsToIsoReplacements()

public getFormatsToIsoReplacements() : array<string|int, mixed>

List of replacements from date() format to isoFormat().

Return values
array<string|int, mixed>

getHumanDiffOptions()

public getHumanDiffOptions() : int
Return values
int

getIsoUnits()

public getIsoUnits() : array<string|int, mixed>

Returns list of locale units for ISO formatting.

Return values
array<string|int, mixed>

getIsoUnits()

public getIsoUnits() : array<string|int, mixed>

Returns list of locale units for ISO formatting.

Return values
array<string|int, mixed>

getLastErrors()

public getLastErrors() : array<string|int, mixed>|false
Return values
array<string|int, mixed>|false

getLastErrors()

public getLastErrors() : array<string|int, mixed>|false
Return values
array<string|int, mixed>|false

getLocale()

public getLocale() : string

Get the current translator locale.

Return values
string

getLocale()

public getLocale() : string

Get the current translator locale.

Return values
string

getMacro()

Get the raw callable macro registered globally for a given name.

public getMacro(string $name) : callable|null
Parameters
$name : string
Return values
callable|null

getMidDayAt()

public getMidDayAt() : int

get midday/noon hour

Return values
int

getMidDayAt()

public getMidDayAt() : int

get midday/noon hour

Return values
int

getSettings()

public getSettings() : array<string|int, mixed>
Return values
array<string|int, mixed>

getTestNow()

Get the Carbon instance (real or mock) to be returned when a "now" instance is created.

public getTestNow() : Closure|CarbonInterface|null
Return values
Closure|CarbonInterface|null

the current instance used for testing

getTimeFormatByPrecision()

public getTimeFormatByPrecision(string $unitPrecision) : string

Return a format from H:i to H:i:s.u according to given unit precision.

Parameters
$unitPrecision : string
Return values
string

getTimeFormatByPrecision()

public getTimeFormatByPrecision(string $unitPrecision) : string

Return a format from H:i to H:i:s.u according to given unit precision.

Parameters
$unitPrecision : string
Return values
string

getTranslationMessageWith()

public getTranslationMessageWith(mixed $translator, string $key, string|null $locale = null, string|null $default = null) : string|Closure|null

Returns raw translation message for a given key.

Parameters
$translator : mixed
$key : string
$locale = null : string|null
$default = null : string|null
Return values
string|Closure|null

getTranslationMessageWith()

public getTranslationMessageWith(mixed $translator, string $key, string|null $locale = null, string|null $default = null) : string|Closure|null

Returns raw translation message for a given key.

Parameters
$translator : mixed
$key : string
$locale = null : string|null
$default = null : string|null
Return values
string|Closure|null

getTranslator()

Initialize the default translator instance if necessary.

public getTranslator() : TranslatorInterface
Return values
TranslatorInterface

getWeekendDays()

Get weekend days

public getWeekendDays() : array<string|int, mixed>
Return values
array<string|int, mixed>

getWeekEndsAt()

public getWeekEndsAt(string|null $locale = null) : int

Get the last day of week.

Parameters
$locale = null : string|null
Return values
int

getWeekEndsAt()

public getWeekEndsAt(string|null $locale = null) : int

Get the last day of week.

Parameters
$locale = null : string|null
Return values
int

getWeekStartsAt()

public getWeekStartsAt(string|null $locale = null) : int

Get the first day of week.

Parameters
$locale = null : string|null
Return values
int

getWeekStartsAt()

public getWeekStartsAt(string|null $locale = null) : int

Get the first day of week.

Parameters
$locale = null : string|null
Return values
int

hasFormat()

Checks if the (date)time string is in a given format.

public hasFormat(string $date, string $format) : bool
Parameters
$date : string
$format : string
Tags
example
Carbon::hasFormat('11:12:45', 'h:i:s'); // true
Carbon::hasFormat('13:12:45', 'h:i:s'); // false
Return values
bool

hasFormatWithModifiers()

Checks if the (date)time string is in a given format.

public hasFormatWithModifiers(string $date, string $format) : bool
Parameters
$date : string
$format : string
Tags
example
Carbon::hasFormatWithModifiers('31/08/2015', 'd#m#Y'); // true
Carbon::hasFormatWithModifiers('31/08/2015', 'm#d#Y'); // false
Return values
bool

hasMacro()

Checks if macro is registered globally.

public hasMacro(string $name) : bool
Parameters
$name : string
Return values
bool

hasRelativeKeywords()

public hasRelativeKeywords(string|null $time) : bool

Determine if a time string will produce a relative date.

Parameters
$time : string|null
Return values
bool

hasRelativeKeywords()

public hasRelativeKeywords(string|null $time) : bool

Determine if a time string will produce a relative date.

Parameters
$time : string|null
Return values
bool

hasTestNow()

Determine if there is a valid test instance set. A valid test instance is anything that is not null.

public hasTestNow() : bool
Return values
bool

true if there is a test instance, otherwise false

instance()

public instance(DateTimeInterface $date) : Carbon

Create a Carbon instance from a DateTime one.

Parameters
$date : DateTimeInterface
Return values
Carbon

isImmutable()

public isImmutable() : bool

Returns true if the current class/instance is immutable.

Return values
bool

isImmutable()

public isImmutable() : bool

Returns true if the current class/instance is immutable.

Return values
bool

isModifiableUnit()

public isModifiableUnit(mixed $unit) : bool

Returns true if a property can be changed via setter.

Parameters
$unit : mixed
Return values
bool

isModifiableUnit()

public isModifiableUnit(mixed $unit) : bool

Returns true if a property can be changed via setter.

Parameters
$unit : mixed
Return values
bool

isMutable()

public isMutable() : bool

Returns true if the current class/instance is mutable.

Return values
bool

isMutable()

public isMutable() : bool

Returns true if the current class/instance is mutable.

Return values
bool

isStrictModeEnabled()

Returns true if the strict mode is globally in use, false else.

public isStrictModeEnabled() : bool

(It can be overridden in specific instances.)

Return values
bool

localeHasDiffOneDayWords()

public localeHasDiffOneDayWords(string $locale) : bool

Returns true if the given locale is internally supported and has words for 1-day diff (just now, yesterday, tomorrow). Support is considered enabled if the 3 words are translated in the given locale.

Parameters
$locale : string
Return values
bool

localeHasDiffOneDayWords()

public localeHasDiffOneDayWords(string $locale) : bool

Returns true if the given locale is internally supported and has words for 1-day diff (just now, yesterday, tomorrow). Support is considered enabled if the 3 words are translated in the given locale.

Parameters
$locale : string
Return values
bool

localeHasDiffSyntax()

public localeHasDiffSyntax(string $locale) : bool

Returns true if the given locale is internally supported and has diff syntax support (ago, from now, before, after). Support is considered enabled if the 4 sentences are translated in the given locale.

Parameters
$locale : string
Return values
bool

localeHasDiffSyntax()

public localeHasDiffSyntax(string $locale) : bool

Returns true if the given locale is internally supported and has diff syntax support (ago, from now, before, after). Support is considered enabled if the 4 sentences are translated in the given locale.

Parameters
$locale : string
Return values
bool

localeHasDiffTwoDayWords()

public localeHasDiffTwoDayWords(string $locale) : bool

Returns true if the given locale is internally supported and has words for 2-days diff (before yesterday, after tomorrow). Support is considered enabled if the 2 words are translated in the given locale.

Parameters
$locale : string
Return values
bool

localeHasDiffTwoDayWords()

public localeHasDiffTwoDayWords(string $locale) : bool

Returns true if the given locale is internally supported and has words for 2-days diff (before yesterday, after tomorrow). Support is considered enabled if the 2 words are translated in the given locale.

Parameters
$locale : string
Return values
bool

localeHasPeriodSyntax()

public localeHasPeriodSyntax(mixed $locale) : bool

Returns true if the given locale is internally supported and has period syntax support (X times, every X, from X, to X). Support is considered enabled if the 4 sentences are translated in the given locale.

Parameters
$locale : mixed
Return values
bool

localeHasPeriodSyntax()

public localeHasPeriodSyntax(mixed $locale) : bool

Returns true if the given locale is internally supported and has period syntax support (X times, every X, from X, to X). Support is considered enabled if the 4 sentences are translated in the given locale.

Parameters
$locale : mixed
Return values
bool

localeHasShortUnits()

public localeHasShortUnits(string $locale) : bool

Returns true if the given locale is internally supported and has short-units support. Support is considered enabled if either year, day or hour has a short variant translated.

Parameters
$locale : string
Return values
bool

localeHasShortUnits()

public localeHasShortUnits(string $locale) : bool

Returns true if the given locale is internally supported and has short-units support. Support is considered enabled if either year, day or hour has a short variant translated.

Parameters
$locale : string
Return values
bool

macro()

Register a custom macro.

public macro(string $name, callable|null $macro) : void

Pass null macro to remove it.

Parameters
$name : string
$macro : callable|null
Tags
example
$userSettings = [
  'locale' => 'pt',
  'timezone' => 'America/Sao_Paulo',
];
$factory->macro('userFormat', function () use ($userSettings) {
  return $this->copy()->locale($userSettings['locale'])->tz($userSettings['timezone'])->calendar();
});
echo $factory->yesterday()->hours(11)->userFormat();

mergeSettings()

public mergeSettings(array<string|int, mixed> $settings) : self
Parameters
$settings : array<string|int, mixed>
Return values
self

mixin()

public mixin(object|string $mixin) : void

Mix another object into the class.

Parameters
$mixin : object|string

mixin()

public mixin(object|string $mixin) : void

Mix another object into the class.

Parameters
$mixin : object|string

now()

public now(DateTimeZone|string|int|null $timezone = null) : Carbon

Get a Carbon instance for the current date and time.

Parameters
$timezone = null : DateTimeZone|string|int|null
Return values
Carbon

now()

Get a Carbon instance for the current date and time.

public now([DateTimeZone|string|int|null $timezone = null ]) : CarbonImmutable
Parameters
$timezone : DateTimeZone|string|int|null = null
Return values
CarbonImmutable

parse()

public parse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null) : CarbonImmutable

Create a carbon instance from a string. This is an alias for the constructor that allows better fluent syntax as it allows you to do Carbon::parse('Monday next week')->fn() rather than (new Carbon('Monday next week'))->fn().

Parameters
$time : DateTimeInterface|WeekDay|Month|string|int|float|null
$timezone = null : DateTimeZone|string|int|null
Return values
CarbonImmutable

parse()

public parse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null) : Carbon

Create a carbon instance from a string. This is an alias for the constructor that allows better fluent syntax as it allows you to do Carbon::parse('Monday next week')->fn() rather than (new Carbon('Monday next week'))->fn().

Parameters
$time : DateTimeInterface|WeekDay|Month|string|int|float|null
$timezone = null : DateTimeZone|string|int|null
Return values
Carbon

parseFromLocale()

public parseFromLocale(string $time, string|null $locale = null, DateTimeZone|string|int|null $timezone = null) : CarbonImmutable

Create a carbon instance from a localized string (in French, Japanese, Arabic, etc.).

Parameters
$time : string
$locale = null : string|null
$timezone = null : DateTimeZone|string|int|null
Return values
CarbonImmutable

parseFromLocale()

public parseFromLocale(string $time, string|null $locale = null, DateTimeZone|string|int|null $timezone = null) : Carbon

Create a carbon instance from a localized string (in French, Japanese, Arabic, etc.).

Parameters
$time : string
$locale = null : string|null
$timezone = null : DateTimeZone|string|int|null
Return values
Carbon

pluralUnit()

public pluralUnit(string $unit) : string

Returns standardized plural of a given singular/plural unit name (in English).

Parameters
$unit : string
Return values
string

pluralUnit()

public pluralUnit(string $unit) : string

Returns standardized plural of a given singular/plural unit name (in English).

Parameters
$unit : string
Return values
string

rawParse()

public rawParse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null) : CarbonImmutable

Create a carbon instance from a string. This is an alias for the constructor that allows better fluent syntax as it allows you to do Carbon::parse('Monday next week')->fn() rather than (new Carbon('Monday next week'))->fn().

Parameters
$time : DateTimeInterface|WeekDay|Month|string|int|float|null
$timezone = null : DateTimeZone|string|int|null
Return values
CarbonImmutable

rawParse()

public rawParse(DateTimeInterface|WeekDay|Month|string|int|float|null $time, DateTimeZone|string|int|null $timezone = null) : Carbon

Create a carbon instance from a string. This is an alias for the constructor that allows better fluent syntax as it allows you to do Carbon::parse('Monday next week')->fn() rather than (new Carbon('Monday next week'))->fn().

Parameters
$time : DateTimeInterface|WeekDay|Month|string|int|float|null
$timezone = null : DateTimeZone|string|int|null
Return values
Carbon

resetMacros()

Remove all macros and generic macros.

public resetMacros() : void

resetMonthsOverflow()

Reset the month overflow behavior.

public resetMonthsOverflow() : void

resetToStringFormat()

Reset the format used to the default when type juggling a Carbon instance to a string

public resetToStringFormat() : void

resetYearsOverflow()

Reset the month overflow behavior.

public resetYearsOverflow() : void

serializeUsing()

JSON serialize all Carbon instances using the given callback.

public serializeUsing(string|callable|null $format) : void
Parameters
$format : string|callable|null

setClassName()

public setClassName(string $className) : self
Parameters
$className : string
Return values
self

setFallbackLocale()

public setFallbackLocale(string $locale) : void

Set the fallback locale.

Parameters
$locale : string

setFallbackLocale()

public setFallbackLocale(string $locale) : void

Set the fallback locale.

Parameters
$locale : string

setHumanDiffOptions()

public setHumanDiffOptions(int $humanDiffOptions) : void
Parameters
$humanDiffOptions : int

setLocale()

public setLocale(string $locale) : void

Set the current translator locale and indicate if the source locale file exists. Pass 'auto' as locale to use the closest language to the current LC_TIME locale.

Parameters
$locale : string

setLocale()

public setLocale(string $locale) : void

Set the current translator locale and indicate if the source locale file exists. Pass 'auto' as locale to use the closest language to the current LC_TIME locale.

Parameters
$locale : string

setMidDayAt()

public setMidDayAt(mixed $hour) : void

@deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather consider mid-day is always 12pm, then if you need to test if it's an other hour, test it explicitly: $date->format('G') == 13 or to set explicitly to a given hour: $date->setTime(13, 0, 0, 0) Set midday/noon hour

Parameters
$hour : mixed

setMidDayAt()

public setMidDayAt(mixed $hour) : void

@deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather consider mid-day is always 12pm, then if you need to test if it's an other hour, test it explicitly: $date->format('G') == 13 or to set explicitly to a given hour: $date->setTime(13, 0, 0, 0) Set midday/noon hour

Parameters
$hour : mixed

setSettings()

public setSettings(array<string|int, mixed> $settings) : self
Parameters
$settings : array<string|int, mixed>
Return values
self

setTestNow()

Set a Carbon instance (real or mock) to be returned when a "now" instance is created. The provided instance will be returned specifically under the following conditions: - A call to the static now() method, ex. Carbon::now() - When a null (or blank string) is passed to the constructor or parse(), ex. new Carbon(null) - When the string "now" is passed to the constructor or parse(), ex. new Carbon('now') - When a string containing the desired time is passed to Carbon::parse().

public setTestNow([DateTimeInterface|Closure|static|string|false|null $testNow = null ]) : void

Note the timezone parameter was left out of the examples above and has no affect as the mock value will be returned regardless of its value.

Only the moment is mocked with setTestNow(), the timezone will still be the one passed as parameter of date_default_timezone_get() as a fallback (see setTestNowAndTimezone()).

To clear the test instance call this method using the default parameter of null.

/!\ Use this method for unit tests only.

Parameters
$testNow : DateTimeInterface|Closure|static|string|false|null = null

real or mock Carbon instance

setTestNowAndTimezone()

Set a Carbon instance (real or mock) to be returned when a "now" instance is created. The provided instance will be returned specifically under the following conditions: - A call to the static now() method, ex. Carbon::now() - When a null (or blank string) is passed to the constructor or parse(), ex. new Carbon(null) - When the string "now" is passed to the constructor or parse(), ex. new Carbon('now') - When a string containing the desired time is passed to Carbon::parse().

public setTestNowAndTimezone([DateTimeInterface|Closure|static|string|false|null $testNow = null ][, mixed $timezone = null ]) : void

It will also align default timezone (e.g. call date_default_timezone_set()) with the second argument or if null, with the timezone of the given date object.

To clear the test instance call this method using the default parameter of null.

/!\ Use this method for unit tests only.

Parameters
$testNow : DateTimeInterface|Closure|static|string|false|null = null

real or mock Carbon instance

$timezone : mixed = null

settings()

public settings([array<string|int, mixed>|null $settings = null ]) : self|array<string|int, mixed>
Parameters
$settings : array<string|int, mixed>|null = null
Return values
self|array<string|int, mixed>

setToStringFormat()

Set the default format used when type juggling a Carbon instance to a string.

public setToStringFormat(string|Closure|null $format) : void
Parameters
$format : string|Closure|null

setTranslator()

Set the default translator instance to use.

public setTranslator(TranslatorInterface $translator) : void
Parameters
$translator : TranslatorInterface

setWeekendDays()

Set weekend days

public setWeekendDays(array<string|int, mixed> $days) : void
Parameters
$days : array<string|int, mixed>

shouldOverflowMonths()

Get the month overflow global behavior (can be overridden in specific instances).

public shouldOverflowMonths() : bool
Return values
bool

shouldOverflowYears()

Get the month overflow global behavior (can be overridden in specific instances).

public shouldOverflowYears() : bool
Return values
bool

singularUnit()

public singularUnit(string $unit) : string

Returns standardized singular of a given singular/plural unit name (in English).

Parameters
$unit : string
Return values
string

singularUnit()

public singularUnit(string $unit) : string

Returns standardized singular of a given singular/plural unit name (in English).

Parameters
$unit : string
Return values
string

sleep()

public sleep(int|float $seconds) : void
Parameters
$seconds : int|float

sleep()

public sleep(int|float $seconds) : void
Parameters
$seconds : int|float

today()

public today(DateTimeZone|string|int|null $timezone = null) : Carbon

Create a Carbon instance for today.

Parameters
$timezone = null : DateTimeZone|string|int|null
Return values
Carbon

tomorrow()

public tomorrow(DateTimeZone|string|int|null $timezone = null) : Carbon

Create a Carbon instance for tomorrow.

Parameters
$timezone = null : DateTimeZone|string|int|null
Return values
Carbon

translateTimeString()

public translateTimeString(string $timeString, string|null $from = null, string|null $to = null, int $mode = CarbonInterface::TRANSLATE_ALL) : string

Translate a time string from a locale to an other.

Parameters
$timeString : string
$from = null : string|null
$to = null : string|null
$mode = CarbonInterface::TRANSLATE_ALL : int
Return values
string

translateTimeString()

public translateTimeString(string $timeString, string|null $from = null, string|null $to = null, int $mode = CarbonInterface::TRANSLATE_ALL) : string

Translate a time string from a locale to an other.

Parameters
$timeString : string
$from = null : string|null
$to = null : string|null
$mode = CarbonInterface::TRANSLATE_ALL : int
Return values
string

translateWith()

public translateWith(TranslatorInterface $translator, string $key, array<string|int, mixed> $parameters = [], mixed $number) : string

Translate using translation string or callback available.

Parameters
$translator : TranslatorInterface
$key : string
$parameters = [] : array<string|int, mixed>
$number : mixed
Return values
string

translateWith()

public translateWith(TranslatorInterface $translator, string $key, array<string|int, mixed> $parameters = [], mixed $number) : string

Translate using translation string or callback available.

Parameters
$translator : TranslatorInterface
$key : string
$parameters = [] : array<string|int, mixed>
$number : mixed
Return values
string

useMonthsOverflow()

Indicates if months should be calculated with overflow.

public useMonthsOverflow([bool $monthsOverflow = true ]) : void
Parameters
$monthsOverflow : bool = true

useStrictMode()

Enable the strict mode (or disable with passing false).

public useStrictMode([bool $strictModeEnabled = true ]) : void
Parameters
$strictModeEnabled : bool = true

useYearsOverflow()

Indicates if years should be calculated with overflow.

public useYearsOverflow([bool $yearsOverflow = true ]) : void
Parameters
$yearsOverflow : bool = true

withTestNow()

Temporarily sets a static date to be used within the callback.

public withTestNow(DateTimeInterface|Closure|static|string|false|null $testNow, callable $callback) : T

Using setTestNow to set the date, executing the callback, then clearing the test instance.

/!\ Use this method for unit tests only.

Parameters
$testNow : DateTimeInterface|Closure|static|string|false|null

real or mock Carbon instance

$callback : callable
Tags
template

T

Return values
T

withTimeZone()

public withTimeZone(DateTimeZone|string|int|null $timezone) : static
Parameters
$timezone : DateTimeZone|string|int|null
Return values
static

yesterday()

public yesterday(DateTimeZone|string|int|null $timezone = null) : CarbonImmutable

Create a Carbon instance for yesterday.

Parameters
$timezone = null : DateTimeZone|string|int|null
Return values
CarbonImmutable

yesterday()

public yesterday(DateTimeZone|string|int|null $timezone = null) : Carbon

Create a Carbon instance for yesterday.

Parameters
$timezone = null : DateTimeZone|string|int|null
Return values
Carbon

getMockedTestNow()

Get the mocked date passed in setTestNow() and if it's a Closure, execute it.

protected getMockedTestNow(DateTimeZone|string|int|null $timezone) : CarbonInterface|null
Parameters
$timezone : DateTimeZone|string|int|null
Return values
CarbonInterface|null

matchFormatPattern()

Checks if the (date)time string is in a given format with given list of pattern replacements.

private matchFormatPattern(string $date, string $format, array<string|int, mixed> $replacements) : bool
Parameters
$date : string
$format : string
$replacements : array<string|int, mixed>
Tags
example
Carbon::hasFormat('11:12:45', 'h:i:s'); // true
Carbon::hasFormat('13:12:45', 'h:i:s'); // false
Return values
bool

setDefaultTimezone()

private setDefaultTimezone(string $timezone[, DateTimeInterface|null $date = null ]) : void
Parameters
$timezone : string
$date : DateTimeInterface|null = null

        
On this page

Search results