FileAccess Orion

CarbonInterval extends DateInterval
in package
Uses IntervalRounding, Mixin, Options

A simple API extension for DateInterval.

The implementation provides helpers to handle weeks but only days are saved. Weeks are calculated based on the total days of the current instance.

Table of Contents

PERIOD_DAYS  = 'D'
PERIOD_HOURS  = 'H'
PERIOD_MINUTES  = 'M'
PERIOD_MONTHS  = 'M'
PERIOD_PREFIX  = 'P'
Interval spec period designators
PERIOD_SECONDS  = 'S'
PERIOD_TIME_PREFIX  = 'T'
PERIOD_YEARS  = 'Y'
$daysExcludeWeeks  : int
$dayz  : int
$dayzExcludeWeeks  : int
$hours  : int
$locale  : string
$microseconds  : int
$milliseconds  : int
$minutes  : int
$months  : int
$PHPIntSize  : int
Customizable PHP_INT_SIZE override.
$seconds  : int
$totalDays  : float
$totalDayz  : float
$totalHours  : float
$totalMicroseconds  : float
$totalMilliseconds  : float
$totalMinutes  : float
$totalMonths  : float
$totalSeconds  : float
$totalWeeks  : float
$totalYears  : float
$weeks  : int
$years  : int
$cascadeFactors  : array<string|int, mixed>|null
$createFromFormatFunction  : string|callable|null
Function to call instead of createFromFormat.
$formatFunction  : string|callable|null
Function to call instead of format.
$formats  : array<string|int, mixed>
$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.
$macroContextStack  : array<string|int, mixed>
Stack of macro instance contexts.
$macros  : array<string|int, mixed>
The registered macros.
$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.
$translator  : TranslatorInterface
A translator to ... er ... translate stuff
$tzName  : mixed
Timezone handler for settings() method.
$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.
$flipCascadeFactors  : array<string|int, mixed>|null
__call()  : static
Allow fluent calls on the setters... CarbonInterval::years(3)->months(5)->day().
__callStatic()  : static|null
Provide static helpers to create instances. Allows CarbonInterval::years(3).
__construct()  : mixed
Create a new CarbonInterval instance.
__debugInfo()  : array<string|int, mixed>
Show truthy properties on var_dump().
__get()  : int|float|string
Get a part of the CarbonInterval object.
__set()  : mixed
Set a part of the CarbonInterval object.
__toString()  : string
Format the instance as a string using the forHumans() function.
add()  : static
Add the passed interval to the current instance.
between()  : bool
Determines if the instance is between two others.
betweenExcluded()  : bool
Determines if the instance is between two others, bounds excluded.
betweenIncluded()  : bool
Determines if the instance is between two others, bounds excluded.
cascade()  : $this
Convert overflowed values into bigger units.
cast()  : DateInterval
Cast the current instance into the given class.
ceil()  : $this
Ceil the current instance second with given precision if specified.
ceilCenturies()  : $this
ceilCentury()  : $this
ceilDay()  : $this
ceilDays()  : $this
ceilDecade()  : $this
ceilDecades()  : $this
ceilHour()  : $this
ceilHours()  : $this
ceilMicrosecond()  : $this
ceilMicroseconds()  : $this
ceilMillennia()  : $this
ceilMillennium()  : $this
ceilMillisecond()  : $this
ceilMilliseconds()  : $this
ceilMinute()  : $this
ceilMinutes()  : $this
ceilMonth()  : $this
ceilMonths()  : $this
ceilQuarter()  : $this
ceilQuarters()  : $this
ceilSecond()  : $this
ceilSeconds()  : $this
ceilUnit()  : $this
Ceil the current instance at the given unit with given precision if specified.
ceilWeek()  : $this
ceilWeeks()  : $this
ceilYear()  : $this
ceilYears()  : $this
clone()  : static
Get a copy of the instance.
compare()  : int
Comparing with passed interval.
compareDateIntervals()  : int
Comparing 2 date intervals.
copy()  : static
Get a copy of the instance.
create()  : static
Create a new CarbonInterval instance from specific values.
createFromDateString()  : static
Sets up a DateInterval from the relative parts of the string.
createFromFormat()  : static
Parse a string into a new CarbonInterval object according to the specified format.
day()  : CarbonInterval
day()  : $this
days()  : CarbonInterval
days()  : $this
dayz()  : CarbonInterval
dayz()  : $this
divide()  : $this
Divide and cascade current instance by a given divider.
eq()  : bool
Determines if the instance is equal to another
equalTo()  : bool
Determines if the instance is equal to another
floor()  : $this
Round the current instance second with given precision if specified.
floorCenturies()  : $this
floorCentury()  : $this
floorDay()  : $this
floorDays()  : $this
floorDecade()  : $this
floorDecades()  : $this
floorHour()  : $this
floorHours()  : $this
floorMicrosecond()  : $this
floorMicroseconds()  : $this
floorMillennia()  : $this
floorMillennium()  : $this
floorMillisecond()  : $this
floorMilliseconds()  : $this
floorMinute()  : $this
floorMinutes()  : $this
floorMonth()  : $this
floorMonths()  : $this
floorQuarter()  : $this
floorQuarters()  : $this
floorSecond()  : $this
floorSeconds()  : $this
floorUnit()  : $this
Truncate the current instance at the given unit with given precision if specified.
floorWeek()  : $this
floorWeeks()  : $this
floorYear()  : $this
floorYears()  : $this
forHumans()  : string
Get the current interval in a human readable format in the current locale.
fromString()  : static
Creates a CarbonInterval from string.
getCascadeFactors()  : array<string|int, mixed>
Mapping of units and factors for cascading.
getDateIntervalSpec()  : string
Get the interval_spec string of a date interval.
getDaysPerWeek()  : int
Returns current config for days per week.
getFactor()  : int|null
Returns the factor for a given source-to-target couple.
getHoursPerDay()  : int
Returns current config for hours per day.
getMicrosecondsPerMillisecond()  : int
Returns current config for microseconds per second.
getMillisecondsPerSecond()  : int
Returns current config for microseconds per second.
getMinutesPerHour()  : int
Returns current config for minutes per hour.
getNonZeroValues()  : array<string|int, int>
Returns interval non-zero values as an array where key are the unit names and values the counts.
getSecondsPerMinute()  : int
Returns current config for seconds per minute.
getSettings()  : array<string|int, mixed>
Returns current local settings.
getValuesSequence()  : array<string|int, int>
Returns interval values as an array where key are the unit names and values the counts from the biggest non-zero one the the smallest non-zero one.
greaterThan()  : bool
Determines if the instance is greater (longer) than another
greaterThanOrEqualTo()  : bool
Determines if the instance is greater (longer) than or equal to another
gt()  : bool
Determines if the instance is greater (longer) than another
gte()  : bool
Determines if the instance is greater (longer) than or equal to another
hasMacro()  : bool
Check if macro is registered.
hour()  : CarbonInterval
hour()  : $this
hours()  : CarbonInterval
hours()  : $this
instance()  : static
Create a CarbonInterval instance from a DateInterval one. Can not instance DateInterval objects created from DateTime::diff() as you can't externally set the $days field.
invert()  : $this
Invert the interval.
isBetween()  : bool
Determines if the instance is between two others
isEmpty()  : bool
Returns true if the interval is empty for each unit.
isStrictModeEnabled()  : bool
Returns true if the strict mode is globally in use, false else.
lessThan()  : bool
Determines if the instance is less (shorter) than another
lessThanOrEqualTo()  : bool
Determines if the instance is less (shorter) than or equal to another
lt()  : bool
Determines if the instance is less (shorter) than another
lte()  : bool
Determines if the instance is less (shorter) than or equal to another
macro()  : void
Register a custom macro.
make()  : static|null
Make a CarbonInterval instance from given variable if possible.
microsecond()  : CarbonInterval
microsecond()  : $this
microseconds()  : CarbonInterval
microseconds()  : $this
millisecond()  : CarbonInterval
millisecond()  : $this
milliseconds()  : CarbonInterval
milliseconds()  : $this
minute()  : CarbonInterval
minute()  : $this
minutes()  : CarbonInterval
minutes()  : $this
mixin()  : void
Register macros from a mixin object.
month()  : CarbonInterval
month()  : $this
months()  : CarbonInterval
months()  : $this
multiply()  : $this
Multiply and cascade current instance by a given factor.
ne()  : bool
Determines if the instance is not equal to another
notEqualTo()  : bool
Determines if the instance is not equal to another
parseFromLocale()  : static
Creates a CarbonInterval from string using a different locale.
resetMonthsOverflow()  : void
resetYearsOverflow()  : void
round()  : $this
Round the current instance second with given precision if specified.
roundCenturies()  : $this
roundCentury()  : $this
roundDay()  : $this
roundDays()  : $this
roundDecade()  : $this
roundDecades()  : $this
roundHour()  : $this
roundHours()  : $this
roundMicrosecond()  : $this
roundMicroseconds()  : $this
roundMillennia()  : $this
roundMillennium()  : $this
roundMillisecond()  : $this
roundMilliseconds()  : $this
roundMinute()  : $this
roundMinutes()  : $this
roundMonth()  : $this
roundMonths()  : $this
roundQuarter()  : $this
roundQuarters()  : $this
roundSecond()  : $this
roundSeconds()  : $this
roundUnit()  : $this
Round the current instance at the given unit with given precision if specified and the given function.
roundWeek()  : $this
roundWeeks()  : $this
roundYear()  : $this
roundYears()  : $this
second()  : CarbonInterval
second()  : $this
seconds()  : CarbonInterval
seconds()  : $this
setCascadeFactors()  : mixed
Set default cascading factors for ->cascade() method.
settings()  : $this|static
Set specific options.
shares()  : $this
Divide current instance by a given divider. shares() is naive, it divides each unit separately and the result is rounded for each unit. So 5 hours and 20 minutes shared by 3 becomes 2 hours and 7 minutes.
shiftTimezone()  : static
Set the instance's timezone from a string or object and add/subtract the offset difference.
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).
spec()  : string
Get the interval_spec string.
sub()  : static
Subtract the passed interval to the current instance.
subtract()  : static
Subtract the passed interval to the current instance.
times()  : $this
Multiply current instance given number of times. times() is naive, it multiplies each unit (so day can be greater than 31, hour can be greater than 23, etc.) and the result is rounded separately for each unit.
toArray()  : array<string|int, int>
Returns interval values as an array where key are the unit names and values the counts.
toDateInterval()  : DateInterval
Return native DateInterval PHP object matching the current instance.
toPeriod()  : CarbonPeriod
Convert the interval to a CarbonPeriod.
total()  : float
Get amount of given unit equivalent to the interval.
useMonthsOverflow()  : void
useStrictMode()  : mixed
useYearsOverflow()  : void
week()  : CarbonInterval
week()  : $this
weeks()  : CarbonInterval
weeks()  : $this
weeksAndDays()  : static
Allow setting of weeks and days to be cumulative.
year()  : CarbonInterval
year()  : $this
years()  : CarbonInterval
years()  : $this
bindMacroContext()  : mixed
Stack a Carbon context from inside calls of self::this() and execute a given action.
callMacro()  : mixed
Call given macro.
callRoundMethod()  : mixed
copyProperties()  : mixed
getForHumansInitialVariables()  : mixed
getForHumansParameters()  : array<string|int, mixed>
getRoundingMethodFromOptions()  : string|null
makeFromString()  : mixed
resolveInterval()  : mixed
roundWith()  : mixed
solveNegativeInterval()  : mixed
this()  : static
Return the current context from inside a macro callee or a new one if static.
castIntervalToClass()  : mixed
copyNegativeUnits()  : mixed
getFlipCascadeFactors()  : mixed
loadMixinClass()  : mixed
loadMixinTrait()  : mixed
standardizeUnit()  : mixed

Constants

PERIOD_PREFIX

Interval spec period designators

public mixed PERIOD_PREFIX = 'P'

Properties

$daysExcludeWeeks read-only

public int $daysExcludeWeeks

alias of dayzExcludeWeeks

$dayz

public int $dayz

Total days of the current interval (weeks * 7 + days).

$dayzExcludeWeeks read-only

public int $dayzExcludeWeeks

Total days remaining in the final week of the current instance (days % 7).

$locale read-only

public string $locale

locale of the current instance

$microseconds

public int $microseconds

Total microseconds of the current interval.

$milliseconds

public int $milliseconds

Total microseconds of the current interval.

$minutes

public int $minutes

Total minutes of the current interval.

$PHPIntSize

Customizable PHP_INT_SIZE override.

public static int $PHPIntSize = PHP_INT_SIZE

$seconds

public int $seconds

Total seconds of the current interval.

$totalDays read-only

public float $totalDays

Number of days equivalent to the interval.

$totalDayz read-only

public float $totalDayz

Alias for totalDays.

$totalHours read-only

public float $totalHours

Number of hours equivalent to the interval.

$totalMicroseconds read-only

public float $totalMicroseconds

Number of microseconds equivalent to the interval.

$totalMilliseconds read-only

public float $totalMilliseconds

Number of milliseconds equivalent to the interval.

$totalMinutes read-only

public float $totalMinutes

Number of minutes equivalent to the interval.

$totalMonths read-only

public float $totalMonths

Number of months equivalent to the interval.

$totalSeconds read-only

public float $totalSeconds

Number of seconds equivalent to the interval.

$totalWeeks read-only

public float $totalWeeks

Number of weeks equivalent to the interval.

$totalYears read-only

public float $totalYears

Number of years equivalent to the interval.

$weeks

public int $weeks

Total weeks of the current interval calculated from the days.

$cascadeFactors

protected static array<string|int, mixed>|null $cascadeFactors

$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

$formats

protected static array<string|int, mixed> $formats = ['y' => 'y', 'Y' => 'y', 'o' => 'y', 'm' => 'm', 'n' => 'm', 'W' => 'weeks', 'd' => 'd', 'j' => 'd', 'z' => 'd', 'h' => 'h', 'g' => 'h', 'H' => 'h', 'G' => 'h', 'i' => 'i', 's' => 's', 'u' => 'micro', 'v' => 'milli']

$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.

$macroContextStack

Stack of macro instance contexts.

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

$macros

The registered macros.

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

$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.

$tzName

Timezone handler for settings() method.

protected mixed $tzName

$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.

$flipCascadeFactors

private static array<string|int, mixed>|null $flipCascadeFactors

Methods

__call()

Allow fluent calls on the setters... CarbonInterval::years(3)->months(5)->day().

public __call(string $method, array<string|int, mixed> $parameters) : static

Note: This is done using the magic method to allow static and instance methods to have the same names.

Parameters
$method : string

magic method name called

$parameters : array<string|int, mixed>

parameters list

Tags
throws
BadFluentSetterException|Throwable
Return values
static —

__callStatic()

Provide static helpers to create instances. Allows CarbonInterval::years(3).

public static __callStatic(string $method, array<string|int, mixed> $parameters) : static|null

Note: This is done using the magic method to allow static and instance methods to have the same names.

Parameters
$method : string

magic method name called

$parameters : array<string|int, mixed>

parameters list

Return values
static|null —

__construct()

Create a new CarbonInterval instance.

public __construct([int|null $years = 1 ][, int|null $months = null ][, int|null $weeks = null ][, int|null $days = null ][, int|null $hours = null ][, int|null $minutes = null ][, int|null $seconds = null ][, int|null $microseconds = null ]) : mixed
Parameters
$years : int|null = 1
$months : int|null = null
$weeks : int|null = null
$days : int|null = null
$hours : int|null = null
$minutes : int|null = null
$seconds : int|null = null
$microseconds : int|null = null
Tags
throws
Exception

when the interval_spec (passed as $years) cannot be parsed as an interval.

Return values
mixed —

__debugInfo()

Show truthy properties on var_dump().

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

__get()

Get a part of the CarbonInterval object.

public __get(string $name) : int|float|string
Parameters
$name : string
Tags
throws
UnknownGetterException
Return values
int|float|string —

__set()

Set a part of the CarbonInterval object.

public __set(string $name, int $value) : mixed
Parameters
$name : string
$value : int
Tags
throws
UnknownSetterException
Return values
mixed —

__toString()

Format the instance as a string using the forHumans() function.

public __toString() : string
Tags
throws
Exception
Return values
string —

add()

Add the passed interval to the current instance.

public add(string|DateInterval $unit[, int $value = 1 ]) : static
Parameters
$unit : string|DateInterval
$value : int = 1
Return values
static —

between()

Determines if the instance is between two others.

public between(CarbonInterval|DateInterval|mixed $interval1, CarbonInterval|DateInterval|mixed $interval2[, bool $equal = true ]) : bool

The third argument allow you to specify if bounds are included or not (true by default) but for when you including/excluding bounds may produce different results in your application, we recommend to use the explicit methods ->betweenIncluded() or ->betweenExcluded() instead.

Parameters
$interval1 : CarbonInterval|DateInterval|mixed
$interval2 : CarbonInterval|DateInterval|mixed
$equal : bool = true

Indicates if an equal to comparison should be done

Tags
example
CarbonInterval::hours(48)->between(CarbonInterval::day(), CarbonInterval::days(3)); // true
CarbonInterval::hours(48)->between(CarbonInterval::day(), CarbonInterval::hours(36)); // false
CarbonInterval::hours(48)->between(CarbonInterval::day(), CarbonInterval::days(2)); // true
CarbonInterval::hours(48)->between(CarbonInterval::day(), CarbonInterval::days(2), false); // false
Return values
bool —

betweenExcluded()

Determines if the instance is between two others, bounds excluded.

public betweenExcluded(CarbonInterval|DateInterval|mixed $interval1, CarbonInterval|DateInterval|mixed $interval2) : bool
Parameters
$interval1 : CarbonInterval|DateInterval|mixed
$interval2 : CarbonInterval|DateInterval|mixed
Tags
example
CarbonInterval::hours(48)->betweenExcluded(CarbonInterval::day(), CarbonInterval::days(3)); // true
CarbonInterval::hours(48)->betweenExcluded(CarbonInterval::day(), CarbonInterval::hours(36)); // false
CarbonInterval::hours(48)->betweenExcluded(CarbonInterval::day(), CarbonInterval::days(2)); // false
Return values
bool —

betweenIncluded()

Determines if the instance is between two others, bounds excluded.

public betweenIncluded(CarbonInterval|DateInterval|mixed $interval1, CarbonInterval|DateInterval|mixed $interval2) : bool
Parameters
$interval1 : CarbonInterval|DateInterval|mixed
$interval2 : CarbonInterval|DateInterval|mixed
Tags
example
CarbonInterval::hours(48)->betweenExcluded(CarbonInterval::day(), CarbonInterval::days(3)); // true
CarbonInterval::hours(48)->betweenExcluded(CarbonInterval::day(), CarbonInterval::hours(36)); // false
CarbonInterval::hours(48)->betweenExcluded(CarbonInterval::day(), CarbonInterval::days(2)); // true
Return values
bool —

cascade()

Convert overflowed values into bigger units.

public cascade() : $this
Return values
$this —

cast()

Cast the current instance into the given class.

public cast(string $className) : DateInterval
Parameters
$className : string

The $className::instance() method will be called to cast the current object.

Return values
DateInterval —

ceil()

Ceil the current instance second with given precision if specified.

public ceil([float|int|string|DateInterval|null $precision = 1 ]) : $this
Parameters
$precision : float|int|string|DateInterval|null = 1
Tags
throws
Exception
Return values
$this —

ceilCenturies()

public ceilCenturies(float $precision = 1) : $this

Ceil the current instance century with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilCentury()

public ceilCentury(float $precision = 1) : $this

Ceil the current instance century with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilDay()

public ceilDay(float $precision = 1) : $this

Ceil the current instance day with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilDays()

public ceilDays(float $precision = 1) : $this

Ceil the current instance day with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilDecade()

public ceilDecade(float $precision = 1) : $this

Ceil the current instance decade with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilDecades()

public ceilDecades(float $precision = 1) : $this

Ceil the current instance decade with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilHour()

public ceilHour(float $precision = 1) : $this

Ceil the current instance hour with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilHours()

public ceilHours(float $precision = 1) : $this

Ceil the current instance hour with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilMicrosecond()

public ceilMicrosecond(float $precision = 1) : $this

Ceil the current instance microsecond with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilMicroseconds()

public ceilMicroseconds(float $precision = 1) : $this

Ceil the current instance microsecond with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilMillennia()

public ceilMillennia(float $precision = 1) : $this

Ceil the current instance millennium with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilMillennium()

public ceilMillennium(float $precision = 1) : $this

Ceil the current instance millennium with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilMillisecond()

public ceilMillisecond(float $precision = 1) : $this

Ceil the current instance millisecond with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilMilliseconds()

public ceilMilliseconds(float $precision = 1) : $this

Ceil the current instance millisecond with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilMinute()

public ceilMinute(float $precision = 1) : $this

Ceil the current instance minute with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilMinutes()

public ceilMinutes(float $precision = 1) : $this

Ceil the current instance minute with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilMonth()

public ceilMonth(float $precision = 1) : $this

Ceil the current instance month with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilMonths()

public ceilMonths(float $precision = 1) : $this

Ceil the current instance month with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilQuarter()

public ceilQuarter(float $precision = 1) : $this

Ceil the current instance quarter with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilQuarters()

public ceilQuarters(float $precision = 1) : $this

Ceil the current instance quarter with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilSecond()

public ceilSecond(float $precision = 1) : $this

Ceil the current instance second with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilSeconds()

public ceilSeconds(float $precision = 1) : $this

Ceil the current instance second with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilUnit()

Ceil the current instance at the given unit with given precision if specified.

public ceilUnit(string $unit[, float|int|string|DateInterval|null $precision = 1 ]) : $this
Parameters
$unit : string
$precision : float|int|string|DateInterval|null = 1
Tags
throws
Exception
Return values
$this —

ceilWeek()

public ceilWeek(float $precision = 1) : $this

Ceil the current instance day with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilWeeks()

public ceilWeeks(float $precision = 1) : $this

Ceil the current instance day with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilYear()

public ceilYear(float $precision = 1) : $this

Ceil the current instance year with given precision.

Parameters
$precision = 1 : float
Return values
$this —

ceilYears()

public ceilYears(float $precision = 1) : $this

Ceil the current instance year with given precision.

Parameters
$precision = 1 : float
Return values
$this —

clone()

Get a copy of the instance.

public clone() : static
Return values
static —

compare()

Comparing with passed interval.

public compare(DateInterval $interval) : int
Parameters
$interval : DateInterval
Return values
int —

compareDateIntervals()

Comparing 2 date intervals.

public static compareDateIntervals(DateInterval $first, DateInterval $second) : int
Parameters
$first : DateInterval
$second : DateInterval
Return values
int —

copy()

Get a copy of the instance.

public copy() : static
Return values
static —

create()

Create a new CarbonInterval instance from specific values.

public static create([int $years = 1 ][, int $months = null ][, int $weeks = null ][, int $days = null ][, int $hours = null ][, int $minutes = null ][, int $seconds = null ][, int $microseconds = null ]) : static

This is an alias for the constructor that allows better fluent syntax as it allows you to do CarbonInterval::create(1)->fn() rather than (new CarbonInterval(1))->fn().

Parameters
$years : int = 1
$months : int = null
$weeks : int = null
$days : int = null
$hours : int = null
$minutes : int = null
$seconds : int = null
$microseconds : int = null
Tags
throws
Exception

when the interval_spec (passed as $years) cannot be parsed as an interval.

Return values
static —

createFromFormat()

Parse a string into a new CarbonInterval object according to the specified format.

public static createFromFormat(string $format, string $interval) : static
Parameters
$format : string

Format of the $interval input string

$interval : string

Input string to convert into an interval

Tags
example
echo Carboninterval::createFromFormat('H:i', '1:30');
throws
Exception

when the $interval cannot be parsed as an interval.

Return values
static —

day()

public day(mixed $days) : $this

Alias for days().

Parameters
$days : mixed
Return values
$this —

days()

public days(mixed $days) : $this

Set the days portion of the current interval.

Parameters
$days : mixed
Return values
$this —

dayz()

public dayz(mixed $days) : $this

Alias for days().

Parameters
$days : mixed
Return values
$this —

divide()

Divide and cascade current instance by a given divider.

public divide(float|int $divider) : $this
Parameters
$divider : float|int
Return values
$this —

eq()

Determines if the instance is equal to another

public eq(CarbonInterval|DateInterval|mixed $interval) : bool
Parameters
$interval : CarbonInterval|DateInterval|mixed
Tags
see
equalTo()
Return values
bool —

equalTo()

Determines if the instance is equal to another

public equalTo(CarbonInterval|DateInterval|mixed $interval) : bool
Parameters
$interval : CarbonInterval|DateInterval|mixed
Return values
bool —

floor()

Round the current instance second with given precision if specified.

public floor([float|int|string|DateInterval|null $precision = 1 ]) : $this
Parameters
$precision : float|int|string|DateInterval|null = 1
Tags
throws
Exception
Return values
$this —

floorCenturies()

public floorCenturies(float $precision = 1) : $this

Truncate the current instance century with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorCentury()

public floorCentury(float $precision = 1) : $this

Truncate the current instance century with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorDay()

public floorDay(float $precision = 1) : $this

Truncate the current instance day with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorDays()

public floorDays(float $precision = 1) : $this

Truncate the current instance day with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorDecade()

public floorDecade(float $precision = 1) : $this

Truncate the current instance decade with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorDecades()

public floorDecades(float $precision = 1) : $this

Truncate the current instance decade with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorHour()

public floorHour(float $precision = 1) : $this

Truncate the current instance hour with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorHours()

public floorHours(float $precision = 1) : $this

Truncate the current instance hour with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorMicrosecond()

public floorMicrosecond(float $precision = 1) : $this

Truncate the current instance microsecond with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorMicroseconds()

public floorMicroseconds(float $precision = 1) : $this

Truncate the current instance microsecond with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorMillennia()

public floorMillennia(float $precision = 1) : $this

Truncate the current instance millennium with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorMillennium()

public floorMillennium(float $precision = 1) : $this

Truncate the current instance millennium with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorMillisecond()

public floorMillisecond(float $precision = 1) : $this

Truncate the current instance millisecond with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorMilliseconds()

public floorMilliseconds(float $precision = 1) : $this

Truncate the current instance millisecond with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorMinute()

public floorMinute(float $precision = 1) : $this

Truncate the current instance minute with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorMinutes()

public floorMinutes(float $precision = 1) : $this

Truncate the current instance minute with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorMonth()

public floorMonth(float $precision = 1) : $this

Truncate the current instance month with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorMonths()

public floorMonths(float $precision = 1) : $this

Truncate the current instance month with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorQuarter()

public floorQuarter(float $precision = 1) : $this

Truncate the current instance quarter with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorQuarters()

public floorQuarters(float $precision = 1) : $this

Truncate the current instance quarter with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorSecond()

public floorSecond(float $precision = 1) : $this

Truncate the current instance second with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorSeconds()

public floorSeconds(float $precision = 1) : $this

Truncate the current instance second with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorUnit()

Truncate the current instance at the given unit with given precision if specified.

public floorUnit(string $unit[, float|int|string|DateInterval|null $precision = 1 ]) : $this
Parameters
$unit : string
$precision : float|int|string|DateInterval|null = 1
Tags
throws
Exception
Return values
$this —

floorWeek()

public floorWeek(float $precision = 1) : $this

Truncate the current instance day with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorWeeks()

public floorWeeks(float $precision = 1) : $this

Truncate the current instance day with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorYear()

public floorYear(float $precision = 1) : $this

Truncate the current instance year with given precision.

Parameters
$precision = 1 : float
Return values
$this —

floorYears()

public floorYears(float $precision = 1) : $this

Truncate the current instance year with given precision.

Parameters
$precision = 1 : float
Return values
$this —

forHumans()

Get the current interval in a human readable format in the current locale.

public forHumans([int|array<string|int, mixed> $syntax = null ][, bool $short = false ][, int $parts = -1 ][, int $options = null ]) : string
Parameters
$syntax : int|array<string|int, mixed> = null

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)
  • 'aUnit' entry, prefer "an hour" over "1 hour" if true
  • '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
  • 'minimumUnit' entry determines the smallest unit of time to display can be long or ` short form of the units, e.g. 'hour' or 'h' (default value: s) 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
$short : bool = false

displays short format of time units

$parts : int = -1

maximum number of parts to display (default value: -1: no limits)

$options : int = null

human diff options

Tags
example
echo CarbonInterval::fromString('4d 3h 40m')->forHumans() . "\n";
echo CarbonInterval::fromString('4d 3h 40m')->forHumans(['parts' => 2]) . "\n";
echo CarbonInterval::fromString('4d 3h 40m')->forHumans(['parts' => 3, 'join' => true]) . "\n";
echo CarbonInterval::fromString('4d 3h 40m')->forHumans(['short' => true]) . "\n";
echo CarbonInterval::fromString('1d 24h')->forHumans(['join' => ' or ']) . "\n";
echo CarbonInterval::fromString('1d 24h')->forHumans(['minimumUnit' => 'hour']) . "\n";
throws
Exception
Return values
string —

fromString()

Creates a CarbonInterval from string.

public static fromString(string $intervalDefinition) : static

Format:

Suffix | Unit | Example | DateInterval expression -------|---------|---------|------------------------ y | years | 1y | P1Y mo | months | 3mo | P3M w | weeks | 2w | P2W d | days | 28d | P28D h | hours | 4h | PT4H m | minutes | 12m | PT12M s | seconds | 59s | PT59S

e. g. 1w 3d 4h 32m 23s is converted to 10 days 4 hours 32 minutes and 23 seconds.

Special cases:

  • An empty string will return a zero interval
  • Fractions are allowed for weeks, days, hours and minutes and will be converted and rounded to the next smaller value (caution: 0.5w = 4d)
Parameters
$intervalDefinition : string
Return values
static —

getCascadeFactors()

Mapping of units and factors for cascading.

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

Should only be modified by changing the factors or referenced constants.

Return values
array<string|int, mixed> —

getDateIntervalSpec()

Get the interval_spec string of a date interval.

public static getDateIntervalSpec(DateInterval $interval) : string
Parameters
$interval : DateInterval
Return values
string —

getDaysPerWeek()

Returns current config for days per week.

public static getDaysPerWeek() : int
Return values
int —

getFactor()

Returns the factor for a given source-to-target couple.

public static getFactor(string $source, string $target) : int|null
Parameters
$source : string
$target : string
Return values
int|null —

getHoursPerDay()

Returns current config for hours per day.

public static getHoursPerDay() : int
Return values
int —

getMicrosecondsPerMillisecond()

Returns current config for microseconds per second.

public static getMicrosecondsPerMillisecond() : int
Return values
int —

getMillisecondsPerSecond()

Returns current config for microseconds per second.

public static getMillisecondsPerSecond() : int
Return values
int —

getMinutesPerHour()

Returns current config for minutes per hour.

public static getMinutesPerHour() : int
Return values
int —

getNonZeroValues()

Returns interval non-zero values as an array where key are the unit names and values the counts.

public getNonZeroValues() : array<string|int, int>
Return values
array<string|int, int> —

getSecondsPerMinute()

Returns current config for seconds per minute.

public static getSecondsPerMinute() : int
Return values
int —

getSettings()

Returns current local settings.

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

getValuesSequence()

Returns interval values as an array where key are the unit names and values the counts from the biggest non-zero one the the smallest non-zero one.

public getValuesSequence() : array<string|int, int>
Return values
array<string|int, int> —

greaterThan()

Determines if the instance is greater (longer) than another

public greaterThan(CarbonInterval|DateInterval|mixed $interval) : bool
Parameters
$interval : CarbonInterval|DateInterval|mixed
Return values
bool —

greaterThanOrEqualTo()

Determines if the instance is greater (longer) than or equal to another

public greaterThanOrEqualTo(CarbonInterval|DateInterval|mixed $interval) : bool
Parameters
$interval : CarbonInterval|DateInterval|mixed
Return values
bool —

gt()

Determines if the instance is greater (longer) than another

public gt(CarbonInterval|DateInterval|mixed $interval) : bool
Parameters
$interval : CarbonInterval|DateInterval|mixed
Tags
see
greaterThan()
Return values
bool —

gte()

Determines if the instance is greater (longer) than or equal to another

public gte(CarbonInterval|DateInterval|mixed $interval) : bool
Parameters
$interval : CarbonInterval|DateInterval|mixed
Tags
see
greaterThanOrEqualTo()
Return values
bool —

hasMacro()

Check if macro is registered.

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

hour()

public hour(mixed $hours) : $this

Alias for hours().

Parameters
$hours : mixed
Return values
$this —

hours()

public hours(mixed $hours) : $this

Set the hours portion of the current interval.

Parameters
$hours : mixed
Return values
$this —

instance()

Create a CarbonInterval instance from a DateInterval one. Can not instance DateInterval objects created from DateTime::diff() as you can't externally set the $days field.

public static instance(DateInterval $interval) : static
Parameters
$interval : DateInterval
Return values
static —

invert()

Invert the interval.

public invert() : $this
Return values
$this —

isBetween()

Determines if the instance is between two others

public isBetween(CarbonInterval|DateInterval|mixed $interval1, CarbonInterval|DateInterval|mixed $interval2[, bool $equal = true ]) : bool
Parameters
$interval1 : CarbonInterval|DateInterval|mixed
$interval2 : CarbonInterval|DateInterval|mixed
$equal : bool = true

Indicates if an equal to comparison should be done

Tags
example
CarbonInterval::hours(48)->isBetween(CarbonInterval::day(), CarbonInterval::days(3)); // true
CarbonInterval::hours(48)->isBetween(CarbonInterval::day(), CarbonInterval::hours(36)); // false
CarbonInterval::hours(48)->isBetween(CarbonInterval::day(), CarbonInterval::days(2)); // true
CarbonInterval::hours(48)->isBetween(CarbonInterval::day(), CarbonInterval::days(2), false); // false
Return values
bool —

isEmpty()

Returns true if the interval is empty for each unit.

public isEmpty() : bool
Return values
bool —

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 —

lessThan()

Determines if the instance is less (shorter) than another

public lessThan(CarbonInterval|DateInterval|mixed $interval) : bool
Parameters
$interval : CarbonInterval|DateInterval|mixed
Return values
bool —

lessThanOrEqualTo()

Determines if the instance is less (shorter) than or equal to another

public lessThanOrEqualTo(CarbonInterval|DateInterval|mixed $interval) : bool
Parameters
$interval : CarbonInterval|DateInterval|mixed
Return values
bool —

lt()

Determines if the instance is less (shorter) than another

public lt(CarbonInterval|DateInterval|mixed $interval) : bool
Parameters
$interval : CarbonInterval|DateInterval|mixed
Tags
see
lessThan()
Return values
bool —

lte()

Determines if the instance is less (shorter) than or equal to another

public lte(CarbonInterval|DateInterval|mixed $interval) : bool
Parameters
$interval : CarbonInterval|DateInterval|mixed
Tags
see
lessThanOrEqualTo()
Return values
bool —

macro()

Register a custom macro.

public static macro(string $name, object|callable $macro) : void
Parameters
$name : string
$macro : object|callable
Tags
example
CarbonInterval::macro('twice', function () {
  return $this->times(2);
});
echo CarbonInterval::hours(2)->twice();
Return values
void —

make()

Make a CarbonInterval instance from given variable if possible.

public static make(mixed|int|DateInterval|string|null $interval[, string|null $unit = null ]) : static|null

Always return a new instance. Parse only strings and only these likely to be intervals (skip dates and recurrences). Throw an exception for invalid format, but otherwise return null.

Parameters
$interval : mixed|int|DateInterval|string|null

interval or number of the given $unit

$unit : string|null = null

if specified, $interval must be an integer

Return values
static|null —

microsecond()

public microsecond(mixed $seconds) : $this

Alias for seconds().

Parameters
$seconds : mixed
Return values
$this —

microseconds()

public microseconds(mixed $seconds) : $this

Set the seconds portion of the current interval.

Parameters
$seconds : mixed
Return values
$this —

millisecond()

public millisecond(mixed $seconds) : $this

Alias for seconds().

Parameters
$seconds : mixed
Return values
$this —

milliseconds()

public milliseconds(mixed $seconds) : $this

Set the seconds portion of the current interval.

Parameters
$seconds : mixed
Return values
$this —

minute()

public minute(mixed $minutes) : $this

Alias for minutes().

Parameters
$minutes : mixed
Return values
$this —

minutes()

public minutes(mixed $minutes) : $this

Set the minutes portion of the current interval.

Parameters
$minutes : mixed
Return values
$this —

mixin()

Register macros from a mixin object.

public static mixin(object|string $mixin) : void
Parameters
$mixin : object|string
Tags
example
CarbonInterval::mixin(new class {
  public function daysToHours() {
    return function () {
      $this->hours += $this->days;
      $this->days = 0;

      return $this;
    };
  }
  public function hoursToDays() {
    return function () {
      $this->days += $this->hours;
      $this->hours = 0;

      return $this;
    };
  }
});
echo CarbonInterval::hours(5)->hoursToDays() . "\n";
echo CarbonInterval::days(5)->daysToHours() . "\n";
throws
ReflectionException
Return values
void —

month()

public month(mixed $months) : $this

Alias for months().

Parameters
$months : mixed
Return values
$this —

months()

public months(mixed $months) : $this

Set the months portion of the current interval.

Parameters
$months : mixed
Return values
$this —

multiply()

Multiply and cascade current instance by a given factor.

public multiply(float|int $factor) : $this
Parameters
$factor : float|int
Return values
$this —

ne()

Determines if the instance is not equal to another

public ne(CarbonInterval|DateInterval|mixed $interval) : bool
Parameters
$interval : CarbonInterval|DateInterval|mixed
Tags
see
notEqualTo()
Return values
bool —

notEqualTo()

Determines if the instance is not equal to another

public notEqualTo(CarbonInterval|DateInterval|mixed $interval) : bool
Parameters
$interval : CarbonInterval|DateInterval|mixed
Return values
bool —

parseFromLocale()

Creates a CarbonInterval from string using a different locale.

public static parseFromLocale(string $interval, string $locale) : static
Parameters
$interval : string
$locale : string
Return values
static —

resetMonthsOverflow()

public static resetMonthsOverflow() : void
Tags
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

Reset the month overflow behavior.

Return values
void —

resetYearsOverflow()

public static resetYearsOverflow() : void
Tags
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

Reset the month overflow behavior.

Return values
void —

round()

Round the current instance second with given precision if specified.

public round([float|int|string|DateInterval|null $precision = 1 ][, string $function = 'round' ]) : $this
Parameters
$precision : float|int|string|DateInterval|null = 1
$function : string = 'round'
Tags
throws
Exception
Return values
$this —

roundCenturies()

public roundCenturies(float $precision = 1, string $function = "round") : $this

Round the current instance century with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundCentury()

public roundCentury(float $precision = 1, string $function = "round") : $this

Round the current instance century with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundDay()

public roundDay(float $precision = 1, string $function = "round") : $this

Round the current instance day with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundDays()

public roundDays(float $precision = 1, string $function = "round") : $this

Round the current instance day with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundDecade()

public roundDecade(float $precision = 1, string $function = "round") : $this

Round the current instance decade with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundDecades()

public roundDecades(float $precision = 1, string $function = "round") : $this

Round the current instance decade with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundHour()

public roundHour(float $precision = 1, string $function = "round") : $this

Round the current instance hour with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundHours()

public roundHours(float $precision = 1, string $function = "round") : $this

Round the current instance hour with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundMicrosecond()

public roundMicrosecond(float $precision = 1, string $function = "round") : $this

Round the current instance microsecond with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundMicroseconds()

public roundMicroseconds(float $precision = 1, string $function = "round") : $this

Round the current instance microsecond with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundMillennia()

public roundMillennia(float $precision = 1, string $function = "round") : $this

Round the current instance millennium with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundMillennium()

public roundMillennium(float $precision = 1, string $function = "round") : $this

Round the current instance millennium with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundMillisecond()

public roundMillisecond(float $precision = 1, string $function = "round") : $this

Round the current instance millisecond with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundMilliseconds()

public roundMilliseconds(float $precision = 1, string $function = "round") : $this

Round the current instance millisecond with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundMinute()

public roundMinute(float $precision = 1, string $function = "round") : $this

Round the current instance minute with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundMinutes()

public roundMinutes(float $precision = 1, string $function = "round") : $this

Round the current instance minute with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundMonth()

public roundMonth(float $precision = 1, string $function = "round") : $this

Round the current instance month with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundMonths()

public roundMonths(float $precision = 1, string $function = "round") : $this

Round the current instance month with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundQuarter()

public roundQuarter(float $precision = 1, string $function = "round") : $this

Round the current instance quarter with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundQuarters()

public roundQuarters(float $precision = 1, string $function = "round") : $this

Round the current instance quarter with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundSecond()

public roundSecond(float $precision = 1, string $function = "round") : $this

Round the current instance second with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundSeconds()

public roundSeconds(float $precision = 1, string $function = "round") : $this

Round the current instance second with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundUnit()

Round the current instance at the given unit with given precision if specified and the given function.

public roundUnit(string $unit[, float|int|string|DateInterval|null $precision = 1 ][, string $function = 'round' ]) : $this
Parameters
$unit : string
$precision : float|int|string|DateInterval|null = 1
$function : string = 'round'
Tags
throws
Exception
Return values
$this —

roundWeek()

public roundWeek(float $precision = 1, string $function = "round") : $this

Round the current instance day with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundWeeks()

public roundWeeks(float $precision = 1, string $function = "round") : $this

Round the current instance day with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundYear()

public roundYear(float $precision = 1, string $function = "round") : $this

Round the current instance year with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

roundYears()

public roundYears(float $precision = 1, string $function = "round") : $this

Round the current instance year with given precision using the given function.

Parameters
$precision = 1 : float
$function = "round" : string
Return values
$this —

second()

public second(mixed $seconds) : $this

Alias for seconds().

Parameters
$seconds : mixed
Return values
$this —

seconds()

public seconds(mixed $seconds) : $this

Set the seconds portion of the current interval.

Parameters
$seconds : mixed
Return values
$this —

setCascadeFactors()

Set default cascading factors for ->cascade() method.

public static setCascadeFactors(array<string|int, mixed> $cascadeFactors) : mixed
Parameters
$cascadeFactors : array<string|int, mixed>
Return values
mixed —

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 —

shares()

Divide current instance by a given divider. shares() is naive, it divides each unit separately and the result is rounded for each unit. So 5 hours and 20 minutes shared by 3 becomes 2 hours and 7 minutes.

public shares(float|int $divider) : $this

Use shares() when you want a fast and approximated calculation that does not cascade units.

For a precise and cascaded calculation,

Parameters
$divider : float|int
Tags
see
divide()
Return values
$this —

shiftTimezone()

Set the instance's timezone from a string or object and add/subtract the offset difference.

public shiftTimezone(DateTimeZone|string $tzName) : static
Parameters
$tzName : DateTimeZone|string
Return values
static —

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 —

spec()

Get the interval_spec string.

public spec() : string
Return values
string —

sub()

Subtract the passed interval to the current instance.

public sub(string|DateInterval $unit[, int $value = 1 ]) : static
Parameters
$unit : string|DateInterval
$value : int = 1
Return values
static —

subtract()

Subtract the passed interval to the current instance.

public subtract(string|DateInterval $unit[, int $value = 1 ]) : static
Parameters
$unit : string|DateInterval
$value : int = 1
Return values
static —

times()

Multiply current instance given number of times. times() is naive, it multiplies each unit (so day can be greater than 31, hour can be greater than 23, etc.) and the result is rounded separately for each unit.

public times(float|int $factor) : $this

Use times() when you want a fast and approximated calculation that does not cascade units.

For a precise and cascaded calculation,

Parameters
$factor : float|int
Tags
see
multiply()
Return values
$this —

toArray()

Returns interval values as an array where key are the unit names and values the counts.

public toArray() : array<string|int, int>
Return values
array<string|int, int> —

toDateInterval()

Return native DateInterval PHP object matching the current instance.

public toDateInterval() : DateInterval
Tags
example
var_dump(CarbonInterval::hours(2)->toDateInterval());
Return values
DateInterval —

toPeriod()

Convert the interval to a CarbonPeriod.

public toPeriod(array<string|int, mixed> ...$params) : CarbonPeriod
Parameters
$params : array<string|int, mixed>

Start date, [end date or recurrences] and optional settings.

Return values
CarbonPeriod —

useMonthsOverflow()

public static useMonthsOverflow([bool $monthsOverflow = true ]) : void
Parameters
$monthsOverflow : bool = true
Tags
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.

Return values
void —

useStrictMode()

public static useStrictMode([bool $strictModeEnabled = true ]) : mixed
Parameters
$strictModeEnabled : bool = true
Tags
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).

Return values
mixed —

useYearsOverflow()

public static useYearsOverflow([bool $yearsOverflow = true ]) : void
Parameters
$yearsOverflow : bool = true
Tags
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.

Return values
void —

week()

public week(mixed $weeks) : $this

Alias for weeks().

Parameters
$weeks : mixed
Return values
$this —

weeks()

public weeks(mixed $weeks) : $this

Set the weeks portion of the current interval. Will overwrite dayz value.

Parameters
$weeks : mixed
Return values
$this —

weeksAndDays()

Allow setting of weeks and days to be cumulative.

public weeksAndDays(int $weeks, int $days) : static
Parameters
$weeks : int

Number of weeks to set

$days : int

Number of days to set

Return values
static —

year()

public year(mixed $years) : $this

Alias for years().

Parameters
$years : mixed
Return values
$this —

years()

public years(mixed $years) : $this

Set the years portion of the current interval.

Parameters
$years : mixed
Return values
$this —

bindMacroContext()

Stack a Carbon context from inside calls of self::this() and execute a given action.

protected static bindMacroContext(static|null $context, callable $callable) : mixed
Parameters
$context : static|null
$callable : callable
Tags
throws
Throwable
Return values
mixed —

callMacro()

Call given macro.

protected callMacro(string $name, array<string|int, mixed> $parameters) : mixed
Parameters
$name : string
$parameters : array<string|int, mixed>
Return values
mixed —

callRoundMethod()

protected callRoundMethod(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string
$parameters : array<string|int, mixed>
Return values
mixed —

copyProperties()

protected copyProperties(self $interval[, mixed $ignoreSign = false ]) : mixed
Parameters
$interval : self
$ignoreSign : mixed = false
Return values
mixed —

getForHumansInitialVariables()

protected getForHumansInitialVariables(mixed $syntax, mixed $short) : mixed
Parameters
$syntax : mixed
$short : mixed
Return values
mixed —

getForHumansParameters()

protected getForHumansParameters([mixed $syntax = null ][, mixed $short = false ][, mixed $parts = -1 ][, mixed $options = null ]) : array<string|int, mixed>
Parameters
$syntax : mixed = null
$short : mixed = false
$parts : mixed = -1
$options : mixed = null
Return values
array<string|int, mixed> —

getRoundingMethodFromOptions()

protected static getRoundingMethodFromOptions(int $options) : string|null
Parameters
$options : int
Return values
string|null —

makeFromString()

protected static makeFromString(string $interval) : mixed
Parameters
$interval : string
Return values
mixed —

resolveInterval()

protected resolveInterval(mixed $interval) : mixed
Parameters
$interval : mixed
Return values
mixed —

roundWith()

protected roundWith(mixed $precision, mixed $function) : mixed
Parameters
$precision : mixed
$function : mixed
Return values
mixed —

solveNegativeInterval()

protected solveNegativeInterval() : mixed
Return values
mixed —

this()

Return the current context from inside a macro callee or a new one if static.

protected static this() : static
Return values
static —

castIntervalToClass()

private static castIntervalToClass(DateInterval $interval, string $className) : mixed
Parameters
$interval : DateInterval
$className : string
Return values
mixed —

copyNegativeUnits()

private static copyNegativeUnits(DateInterval $from, DateInterval $to) : mixed
Parameters
$from : DateInterval
$to : DateInterval
Return values
mixed —

getFlipCascadeFactors()

private static getFlipCascadeFactors() : mixed
Return values
mixed —

loadMixinClass()

private static loadMixinClass(string $mixin) : mixed
Parameters
$mixin : string
Tags
throws
ReflectionException
Return values
mixed —

loadMixinTrait()

private static loadMixinTrait(string $trait) : mixed
Parameters
$trait : string
Return values
mixed —

standardizeUnit()

private static standardizeUnit(mixed $unit) : mixed
Parameters
$unit : mixed
Return values
mixed —

Search results