class Factory

A factory to generate Carbon instances with common settings.

Properties

protected $className
protected $settings

Methods

__construct(array$settings =[],string|null$className =null)

No description

getClassName()

No description

setClassName(string$className)

No description

className(string$className =null)

No description

getSettings()

No description

setSettings(array$settings)

No description

settings(array$settings =null)

No description

mergeSettings(array$settings)

No description

__call($name,$arguments)

No description

bool
canBeCreatedFromFormat($date,$format)

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

Carbon|false
create($year,$month =1,$day =1,$hour,$minute,$second,$tz =null)

Create a new Carbon instance from a specific date and time.

Carbon
createFromDate($year =null,$month =null,$day =null,$tz =null)

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

Carbon|false
createFromFormat($format,$time,$tz =null)

Create a Carbon instance from a specific format.

Carbon|false
createFromIsoFormat($format,$time,$tz =null,$locale ='en',$translator =null)

Create a Carbon instance from a specific ISO format (same replacements as ->isoFormat()).

Carbon|false
createFromLocaleFormat($format,$locale,$time,$tz =null)

Create a Carbon instance from a specific format and a string in a given language.

Carbon|false
createFromLocaleIsoFormat($format,$locale,$time,$tz =null)

Create a Carbon instance from a specific ISO format and a string in a given language.

Carbon
createFromTime($hour,$minute,$second,$tz =null)

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

Carbon
createFromTimeString($time,$tz =null)

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

Carbon
createFromTimestamp($timestamp,$tz =null)

Create a Carbon instance from a timestamp and set the timezone (use default one if not specified).

Carbon
createFromTimestampMs($timestamp,$tz =null)

Create a Carbon instance from a timestamp in milliseconds.

Carbon
createFromTimestampMsUTC($timestamp)

Create a Carbon instance from a timestamp in milliseconds.

Carbon
createFromTimestampUTC($timestamp)

Create a Carbon instance from an timestamp keeping the timezone to UTC.

Carbon
createMidnightDate($year =null,$month =null,$day =null,$tz =null)

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

Carbon|false
createSafe($year =null,$month =null,$day =null,$hour =null,$minute =null,$second =null,$tz =null)

Create a new safe Carbon instance from a specific date and time.

CarbonInterface
createStrict($tz =null)

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

Carbon
disableHumanDiffOption($humanDiffOption)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Carbon
enableHumanDiffOption($humanDiffOption)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

mixed
executeWithLocale($locale,$func)

Set the current locale to the given, execute the passed function, reset the locale to previous one,

Carbon
fromSerialized($value)

Create an instance from a serialized string.

void
genericMacro($macro,$priority)

Register a custom macro.

array
getAvailableLocales()

Returns the list of internally available locales and already loaded custom locales.

array
getDays()

Get the days of the week

string|null
getFallbackLocale()

Get the fallback locale.

array
getFormatsToIsoReplacements()

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

int
getHumanDiffOptions()

Return default humanDiff() options (merged flags as integer).

array
getIsoUnits()

Returns list of locale units for ISO formatting.

array
getLastErrors()

{@inheritdoc}

string
getLocale()

Get the current translator locale.

callable|null
getMacro($name)

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

int
getMidDayAt()

get midday/noon hour

Closure|Carbon
getTestNow()

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

string
getTimeFormatByPrecision($unitPrecision)

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

string
getTranslationMessageWith($translator,string $key)

Returns raw translation message for a given key.

TranslatorInterface
getTranslator()

Get the default translator instance in use.

int
getWeekEndsAt()

Get the last day of week

int
getWeekStartsAt()

Get the first day of week

array
getWeekendDays()

Get weekend days

bool
hasFormat($date,$format)

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

bool
hasFormatWithModifiers($date,$format)

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

bool
hasMacro($name)

Checks if macro is registered globally.

bool
hasRelativeKeywords($time)

Determine if a time string will produce a relative date.

bool
hasTestNow()

Determine if there is a valid test instance set. A valid test instance

Carbon
instance($date)

Create a Carbon instance from a DateTime one.

bool
isImmutable()

Returns true if the current class/instance is immutable.

bool
isModifiableUnit($unit)

Returns true if a property can be changed via setter.

bool
isMutable()

Returns true if the current class/instance is mutable.

bool
isStrictModeEnabled()

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

bool
localeHasDiffOneDayWords($locale)

Returns true if the given locale is internally supported and has words for 1-day diff (just now, yesterday, tomorrow).

bool
localeHasDiffSyntax($locale)

Returns true if the given locale is internally supported and has diff syntax support (ago, from now, before, after).

bool
localeHasDiffTwoDayWords($locale)

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

bool
localeHasPeriodSyntax($locale)

Returns true if the given locale is internally supported and has period syntax support (X times, every X, from X, to X).

bool
localeHasShortUnits($locale)

Returns true if the given locale is internally supported and has short-units support.

void
macro($name,$macro)

Register a custom macro.

Carbon|null
make($var)

Make a Carbon instance from given variable if possible.

Carbon
maxValue()

Create a Carbon instance for the greatest supported date.

Carbon
minValue()

Create a Carbon instance for the lowest supported date.

void
mixin($mixin)

Mix another object into the class.

Carbon
now($tz =null)

Get a Carbon instance for the current date and time.

Carbon
parse($time =null,$tz =null)

Create a carbon instance from a string.

Carbon
parseFromLocale($time,$locale =null,$tz =null)

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

string
pluralUnit(string $unit)

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

Carbon|false
rawCreateFromFormat($format,$time,$tz =null)

Create a Carbon instance from a specific format.

Carbon
rawParse($time =null,$tz =null)

Create a carbon instance from a string.

Carbon
resetMacros()

Remove all macros and generic macros.

void
resetMonthsOverflow()

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

void
resetToStringFormat()

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

void
resetYearsOverflow()

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

void
serializeUsing($callback)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Carbon
setFallbackLocale($locale)

Set the fallback locale.

Carbon
setHumanDiffOptions($humanDiffOptions)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

bool
setLocale($locale)

Set the current translator locale and indicate if the source locale file exists.

void
setMidDayAt($hour)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Carbon
setTestNow($testNow =null)

Set a Carbon instance (real or mock) to be returned when a "now"

Carbon
setTestNowAndTimezone($testNow =null,$tz =null)

Set a Carbon instance (real or mock) to be returned when a "now"

void
setToStringFormat($format)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

void
setTranslator(TranslatorInterface $translator)

Set the default translator instance to use.

Carbon
setUtf8($utf8)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

void
setWeekEndsAt($day)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

void
setWeekStartsAt($day)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

void
setWeekendDays($days)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

bool
shouldOverflowMonths()

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

bool
shouldOverflowYears()

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

string
singularUnit(string $unit)

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

Carbon
today($tz =null)

Create a Carbon instance for today.

Carbon
tomorrow($tz =null)

Create a Carbon instance for tomorrow.

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

Translate a time string from a locale to an other.

string
translateWith(TranslatorInterface $translator,string $key,array $parameters =[],$number =null)

Translate using translation string or callback available.

void
useMonthsOverflow($monthsOverflow =true)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Carbon
useStrictMode($strictModeEnabled =true)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

void
useYearsOverflow($yearsOverflow =true)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

mixed
withTestNow($testNow =null,$callback =null)

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

Carbon
yesterday($tz =null)

Create a Carbon instance for yesterday.

Details

at line248
__construct(array$settings =[],string|null$className =null)

Parameters

array $settings
string|null $className

at line257
getClassName()

at line262
setClassName(string$className)

Parameters

string $className

at line269
className(string$className =null)

Parameters

string $className

at line274
getSettings()

at line279
setSettings(array$settings)

Parameters

array $settings

at line286
settings(array$settings =null)

Parameters

array $settings

at line291
mergeSettings(array$settings)

Parameters

array $settings

at line298
__call($name,$arguments)

Parameters

$name
$arguments

at line242
bool canBeCreatedFromFormat($date,$format)

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

Parameters

$date
$format

Return Value

bool

at line242
Carbon|false create($year,$month =1,$day =1,$hour,$minute,$second,$tz =null)

Create a new Carbon instance from a specific date and time.

Parameters

$year
$month
$day
$hour
$minute
$second
$tz

Return Value

Carbon|false

at line242
Carbon createFromDate($year =null,$month =null,$day =null,$tz =null)

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

Parameters

$year
$month
$day
$tz

Return Value

Carbon

at line242
Carbon|false createFromFormat($format,$time,$tz =null)

Create a Carbon instance from a specific format.

Parameters

$format
$time
$tz

Return Value

Carbon|false

at line242
Carbon|false createFromIsoFormat($format,$time,$tz =null,$locale ='en',$translator =null)

Create a Carbon instance from a specific ISO format (same replacements as ->isoFormat()).

Parameters

$format
$time
$tz
$locale
$translator

Return Value

Carbon|false

at line242
Carbon|false createFromLocaleFormat($format,$locale,$time,$tz =null)

Create a Carbon instance from a specific format and a string in a given language.

Parameters

$format
$locale
$time
$tz

Return Value

Carbon|false

at line242
Carbon|false createFromLocaleIsoFormat($format,$locale,$time,$tz =null)

Create a Carbon instance from a specific ISO format and a string in a given language.

Parameters

$format
$locale
$time
$tz

Return Value

Carbon|false

at line242
Carbon createFromTime($hour,$minute,$second,$tz =null)

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

Parameters

$hour
$minute
$second
$tz

Return Value

Carbon

at line242
Carbon createFromTimeString($time,$tz =null)

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

Parameters

$time
$tz

Return Value

Carbon

at line242
Carbon createFromTimestamp($timestamp,$tz =null)

Create a Carbon instance from a timestamp and set the timezone (use default one if not specified).

Parameters

$timestamp
$tz

Return Value

Carbon

at line242
Carbon createFromTimestampMs($timestamp,$tz =null)

Create a Carbon instance from a timestamp in milliseconds.

Parameters

$timestamp
$tz

Return Value

Carbon

at line242
Carbon createFromTimestampMsUTC($timestamp)

Create a Carbon instance from a timestamp in milliseconds.

Parameters

$timestamp

Return Value

Carbon

at line242
Carbon createFromTimestampUTC($timestamp)

Create a Carbon instance from an timestamp keeping the timezone to UTC.

Parameters

$timestamp

Return Value

Carbon

at line242
Carbon createMidnightDate($year =null,$month =null,$day =null,$tz =null)

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

Parameters

$year
$month
$day
$tz

Return Value

Carbon

at line242
Carbon|false createSafe($year =null,$month =null,$day =null,$hour =null,$minute =null,$second =null,$tz =null)

Create a new safe Carbon instance from a specific date and time.

Parameters

$year
$month
$day
$hour
$minute
$second
$tz

Return Value

Carbon|false

at line242
CarbonInterface createStrict($tz =null)

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

Parameters

$tz

Return Value

CarbonInterface

at line242
Carbon disableHumanDiffOption($humanDiffOption)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Parameters

$humanDiffOption

Return Value

Carbon

at line242
Carbon enableHumanDiffOption($humanDiffOption)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Parameters

$humanDiffOption

Return Value

Carbon

at line242
mixed executeWithLocale($locale,$func)

Set the current locale to the given, execute the passed function, reset the locale to previous one,

Parameters

$locale
$func

Return Value

mixed

at line242
Carbon fromSerialized($value)

Create an instance from a serialized string.

Parameters

$value

Return Value

Carbon

at line242
void genericMacro($macro,$priority)

Register a custom macro.

Parameters

$macro
$priority

Return Value

void

at line242
array getAvailableLocales()

Returns the list of internally available locales and already loaded custom locales.

Return Value

array

at line242
array getDays()

Get the days of the week

Return Value

array

at line242
string|null getFallbackLocale()

Get the fallback locale.

Return Value

string|null

at line242
array getFormatsToIsoReplacements()

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

Return Value

array

at line242
int getHumanDiffOptions()

Return default humanDiff() options (merged flags as integer).

Return Value

int

at line242
array getIsoUnits()

Returns list of locale units for ISO formatting.

Return Value

array

at line242
array getLastErrors()

{@inheritdoc}

Return Value

array

at line242
string getLocale()

Get the current translator locale.

Return Value

string

at line242
callable|null getMacro($name)

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

Parameters

$name

Return Value

callable|null

at line242
int getMidDayAt()

get midday/noon hour

Return Value

int

at line242
Closure|Carbon getTestNow()

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

Return Value

Closure|Carbon

at line242
string getTimeFormatByPrecision($unitPrecision)

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

Parameters

$unitPrecision

Return Value

string

at line242
string getTranslationMessageWith($translator,string $key)

Returns raw translation message for a given key.

Parameters

$translator
string $key

Return Value

string

at line242
TranslatorInterface getTranslator()

Get the default translator instance in use.

Return Value

TranslatorInterface

at line242
int getWeekEndsAt()

Get the last day of week

Return Value

int

at line242
int getWeekStartsAt()

Get the first day of week

Return Value

int

at line242
array getWeekendDays()

Get weekend days

Return Value

array

at line242
bool hasFormat($date,$format)

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

Parameters

$date
$format

Return Value

bool

at line242
bool hasFormatWithModifiers($date,$format)

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

Parameters

$date
$format

Return Value

bool

at line242
bool hasMacro($name)

Checks if macro is registered globally.

Parameters

$name

Return Value

bool

at line242
bool hasRelativeKeywords($time)

Determine if a time string will produce a relative date.

Parameters

$time

Return Value

bool

at line242
bool hasTestNow()

Determine if there is a valid test instance set. A valid test instance

Return Value

bool

at line242
Carbon instance($date)

Create a Carbon instance from a DateTime one.

Parameters

$date

Return Value

Carbon

at line242
bool isImmutable()

Returns true if the current class/instance is immutable.

Return Value

bool

at line242
bool isModifiableUnit($unit)

Returns true if a property can be changed via setter.

Parameters

$unit

Return Value

bool

at line242
bool isMutable()

Returns true if the current class/instance is mutable.

Return Value

bool

at line242
bool isStrictModeEnabled()

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

Return Value

bool

at line242
bool localeHasDiffOneDayWords($locale)

Returns true if the given locale is internally supported and has words for 1-day diff (just now, yesterday, tomorrow).

Parameters

$locale

Return Value

bool

at line242
bool localeHasDiffSyntax($locale)

Returns true if the given locale is internally supported and has diff syntax support (ago, from now, before, after).

Parameters

$locale

Return Value

bool

at line242
bool localeHasDiffTwoDayWords($locale)

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

Parameters

$locale

Return Value

bool

at line242
bool localeHasPeriodSyntax($locale)

Returns true if the given locale is internally supported and has period syntax support (X times, every X, from X, to X).

Parameters

$locale

Return Value

bool

at line242
bool localeHasShortUnits($locale)

Returns true if the given locale is internally supported and has short-units support.

Parameters

$locale

Return Value

bool

at line242
void macro($name,$macro)

Register a custom macro.

Parameters

$name
$macro

Return Value

void

at line242
Carbon|null make($var)

Make a Carbon instance from given variable if possible.

Parameters

$var

Return Value

Carbon|null

at line242
Carbon maxValue()

Create a Carbon instance for the greatest supported date.

Return Value

Carbon

at line242
Carbon minValue()

Create a Carbon instance for the lowest supported date.

Return Value

Carbon

at line242
void mixin($mixin)

Mix another object into the class.

Parameters

$mixin

Return Value

void

at line242
Carbon now($tz =null)

Get a Carbon instance for the current date and time.

Parameters

$tz

Return Value

Carbon

at line242
Carbon parse($time =null,$tz =null)

Create a carbon instance from a string.

Parameters

$time
$tz

Return Value

Carbon

at line242
Carbon parseFromLocale($time,$locale =null,$tz =null)

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

Parameters

$time
$locale
$tz

Return Value

Carbon

at line242
string pluralUnit(string $unit)

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

Parameters

string $unit

Return Value

string

at line242
Carbon|false rawCreateFromFormat($format,$time,$tz =null)

Create a Carbon instance from a specific format.

Parameters

$format
$time
$tz

Return Value

Carbon|false

at line242
Carbon rawParse($time =null,$tz =null)

Create a carbon instance from a string.

Parameters

$time
$tz

Return Value

Carbon

at line242
Carbon resetMacros()

Remove all macros and generic macros.

Return Value

Carbon

at line242
void resetMonthsOverflow()

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Return Value

void

at line242
void resetToStringFormat()

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

Return Value

void

at line242
void resetYearsOverflow()

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Return Value

void

at line242
void serializeUsing($callback)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Parameters

$callback

Return Value

void

at line242
Carbon setFallbackLocale($locale)

Set the fallback locale.

Parameters

$locale

Return Value

Carbon

at line242
Carbon setHumanDiffOptions($humanDiffOptions)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Parameters

$humanDiffOptions

Return Value

Carbon

at line242
bool setLocale($locale)

Set the current translator locale and indicate if the source locale file exists.

Parameters

$locale

Return Value

bool

at line242
void setMidDayAt($hour)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Parameters

$hour

Return Value

void

at line242
Carbon setTestNow($testNow =null)

Set a Carbon instance (real or mock) to be returned when a "now"

Parameters

$testNow

Return Value

Carbon

at line242
Carbon setTestNowAndTimezone($testNow =null,$tz =null)

Set a Carbon instance (real or mock) to be returned when a "now"

Parameters

$testNow
$tz

Return Value

Carbon

at line242
void setToStringFormat($format)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Parameters

$format

Return Value

void

at line242
void setTranslator(TranslatorInterface $translator)

Set the default translator instance to use.

Parameters

TranslatorInterface $translator

Return Value

void

at line242
Carbon setUtf8($utf8)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Parameters

$utf8

Return Value

Carbon

at line242
void setWeekEndsAt($day)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Parameters

$day

Return Value

void

at line242
void setWeekStartsAt($day)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Parameters

$day

Return Value

void

at line242
void setWeekendDays($days)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Parameters

$days

Return Value

void

at line242
bool shouldOverflowMonths()

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

Return Value

bool

at line242
bool shouldOverflowYears()

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

Return Value

bool

at line242
string singularUnit(string $unit)

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

Parameters

string $unit

Return Value

string

at line242
Carbon today($tz =null)

Create a Carbon instance for today.

Parameters

$tz

Return Value

Carbon

at line242
Carbon tomorrow($tz =null)

Create a Carbon instance for tomorrow.

Parameters

$tz

Return Value

Carbon

at line242
string translateTimeString($timeString,$from =null,$to =null,$mode =CarbonInterface::TRANSLATE_ALL)

Translate a time string from a locale to an other.

Parameters

$timeString
$from
$to
$mode

Return Value

string

at line242
string translateWith(TranslatorInterface $translator,string $key,array $parameters =[],$number =null)

Translate using translation string or callback available.

Parameters

TranslatorInterface $translator
string $key
array $parameters
$number

Return Value

string

at line242
void useMonthsOverflow($monthsOverflow =true)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Parameters

$monthsOverflow

Return Value

void

at line242
Carbon useStrictMode($strictModeEnabled =true)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Parameters

$strictModeEnabled

Return Value

Carbon

at line242
void useYearsOverflow($yearsOverflow =true)

@deprecated To avoid conflict between different third-party libraries, static setters should not be used.

Parameters

$yearsOverflow

Return Value

void

at line242
mixed withTestNow($testNow =null,$callback =null)

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

Parameters

$testNow
$callback

Return Value

mixed

at line242
Carbon yesterday($tz =null)

Create a Carbon instance for yesterday.

Parameters

$tz

Return Value

Carbon