Options
Trait Options.
Embed base methods to change settings of Carbon classes.
Depends on the following methods:
Table of Contents
- $PHPIntSize : int
- Customizable PHP_INT_SIZE override.
- $createFromFormatFunction : string|callable|null
- Function to call instead of createFromFormat.
- $formatFunction : string|callable|null
- Function to call instead of format.
- $localFormatFunction : string|callable|null
- Function to call instead of format.
- $localGenericMacros : array<string|int, mixed>|null
- Instance-specific generic macros.
- $localHumanDiffOptions : bool|null
- Options for diffForHumans and forHumans methods.
- $localMacros : array<string|int, mixed>|null
- Instance-specific macros.
- $localMonthsOverflow : bool|null
- Indicates if months should be calculated with overflow.
- $localSerializer : string|null
- Format to use on JSON serialization.
- $localStrictModeEnabled : bool|null
- Indicates if the strict mode is in use.
- $localToStringFormat : string|null
- Format to use on string cast.
- $localYearsOverflow : bool|null
- Indicates if years should be calculated with overflow.
- $monthsOverflow : bool
- Indicates if months should be calculated with overflow.
- $parseFunction : string|callable|null
- Function to call instead of parse.
- $regexFormats : array<string|int, mixed>
- Format regex patterns.
- $strictModeEnabled : bool
- Indicates if the strict mode is in use.
- $weekendDays : array<string|int, mixed>
- Days of weekend.
- $weekEndsAt : int
- Last day of week.
- $weekStartsAt : int
- First day of week.
- $yearsOverflow : bool
- Indicates if years should be calculated with overflow.
- __debugInfo() : array<string|int, mixed>
- Show truthy properties on var_dump().
- getSettings() : array<string|int, mixed>
- Returns current local settings.
- isStrictModeEnabled() : bool
- Returns true if the strict mode is globally in use, false else.
- resetMonthsOverflow() : void
- resetYearsOverflow() : void
- settings() : $this|static
- Set specific options.
- shiftTimezone() : Carbon|CarbonImmutable
- 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).
- useMonthsOverflow() : void
- useStrictMode() : mixed
- useYearsOverflow() : void
Properties
$PHPIntSize
Customizable PHP_INT_SIZE override.
public
static int
$PHPIntSize
= PHP_INT_SIZE
$createFromFormatFunction
Function to call instead of createFromFormat.
protected
static string|callable|null
$createFromFormatFunction
= null
$formatFunction
Function to call instead of format.
protected
static string|callable|null
$formatFunction
= null
$localFormatFunction
Function to call instead of format.
protected
string|callable|null
$localFormatFunction
= null
$localGenericMacros
Instance-specific generic macros.
protected
array<string|int, mixed>|null
$localGenericMacros
= null
$localHumanDiffOptions
Options for diffForHumans and forHumans methods.
protected
bool|null
$localHumanDiffOptions
= null
$localMacros
Instance-specific macros.
protected
array<string|int, mixed>|null
$localMacros
= null
$localMonthsOverflow
Indicates if months should be calculated with overflow.
protected
bool|null
$localMonthsOverflow
= null
Specific setting.
$localSerializer
Format to use on JSON serialization.
protected
string|null
$localSerializer
= null
$localStrictModeEnabled
Indicates if the strict mode is in use.
protected
bool|null
$localStrictModeEnabled
= null
Specific setting.
$localToStringFormat
Format to use on string cast.
protected
string|null
$localToStringFormat
= null
$localYearsOverflow
Indicates if years should be calculated with overflow.
protected
bool|null
$localYearsOverflow
= null
Specific setting.
$monthsOverflow
Indicates if months should be calculated with overflow.
protected
static bool
$monthsOverflow
= true
Global setting.
$parseFunction
Function to call instead of parse.
protected
static string|callable|null
$parseFunction
= null
$regexFormats
Format regex patterns.
protected
static array<string|int, mixed>
$regexFormats
= [
'd' => '(3[01]|[12][0-9]|0[1-9])',
'D' => '([a-zA-Z]{3})',
'j' => '([123][0-9]|[1-9])',
'l' => '([a-zA-Z]{2,})',
'N' => '([1-7])',
'S' => '([a-zA-Z]{2})',
'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]|[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[012]|0[0-9])[0134][05])',
'P' => '([\\+\\-](1[012]|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]|[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]))',
]
$strictModeEnabled
Indicates if the strict mode is in use.
protected
static bool
$strictModeEnabled
= true
Global setting.
$weekendDays
Days of weekend.
protected
static array<string|int, mixed>
$weekendDays
= [\Carbon\CarbonInterface::SATURDAY, \Carbon\CarbonInterface::SUNDAY]
$weekEndsAt
Last day of week.
protected
static int
$weekEndsAt
= \Carbon\CarbonInterface::SUNDAY
$weekStartsAt
First day of week.
protected
static int
$weekStartsAt
= \Carbon\CarbonInterface::MONDAY
$yearsOverflow
Indicates if years should be calculated with overflow.
protected
static bool
$yearsOverflow
= true
Global setting.
Methods
__debugInfo()
Show truthy properties on var_dump().
public
__debugInfo() : array<string|int, mixed>
Return values
array<string|int, mixed> —getSettings()
Returns current local settings.
public
getSettings() : array<string|int, mixed>
Return values
array<string|int, mixed> —isStrictModeEnabled()
Returns true if the strict mode is globally in use, false else.
public
static isStrictModeEnabled() : bool
(It can be overridden in specific instances.)
Return values
bool —resetMonthsOverflow()
public
static resetMonthsOverflow() : void
Tags
Return values
void —resetYearsOverflow()
public
static resetYearsOverflow() : void
Tags
Return values
void —settings()
Set specific options.
public
settings(array<string|int, mixed> $settings) : $this|static
- 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
Parameters
- $settings : array<string|int, mixed>
Return values
$this|static —shiftTimezone()
public
shiftTimezone(mixed $timezone) : Carbon|CarbonImmutable
Set the timezone
Parameters
- $timezone : mixed
Return values
Carbon|CarbonImmutable —shouldOverflowMonths()
Get the month overflow global behavior (can be overridden in specific instances).
public
static shouldOverflowMonths() : bool
Return values
bool —shouldOverflowYears()
Get the month overflow global behavior (can be overridden in specific instances).
public
static shouldOverflowYears() : bool
Return values
bool —useMonthsOverflow()
public
static useMonthsOverflow([bool $monthsOverflow = true ]) : void
Parameters
- $monthsOverflow : bool = true
Tags
Return values
void —useStrictMode()
public
static useStrictMode([bool $strictModeEnabled = true ]) : mixed
Parameters
- $strictModeEnabled : bool = true
Tags
Return values
mixed —useYearsOverflow()
public
static useYearsOverflow([bool $yearsOverflow = true ]) : void
Parameters
- $yearsOverflow : bool = true