class CarbonInterval extendsDateInterval implementsCarbonConverterInterface
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.
Traits
Constants
PERIOD_PREFIX |
Interval spec period designators |
PERIOD_YEARS |
|
PERIOD_MONTHS |
|
PERIOD_DAYS |
|
PERIOD_TIME_PREFIX |
|
PERIOD_HOURS |
|
PERIOD_MINUTES |
|
PERIOD_SECONDS |
|
Properties
protectedClosure|null | $step | Step to apply instead of a fixed interval to get the new date. | from IntervalStep |
staticprotectedarray | $macroContextStack | Stack of macro instance contexts. | from Mixin |
staticprotectedTranslatorInterface | $translator | A translator to . | |
protectedTranslatorInterface | $localTranslator | Specific translator of the current instance. | from Localization |
staticprotectedint | $humanDiffOptions | Options for diffForHumans(). | from Localization |
staticint | $PHPIntSize | Customizable PHP_INT_SIZE override. | from Options |
staticprotectedint|string | $weekStartsAt | First day of week. | from Options |
staticprotectedint|string | $weekEndsAt | Last day of week. | from Options |
staticprotectedarray | $weekendDays | Days of weekend. | from Options |
staticprotectedarray |
$regexFormats | Format regex patterns. | from Options |
staticprotectedarray | $regexFormatModifiers | Format modifiers (such as available in createFromFormat) regex patterns. | from Options |
staticprotectedbool | $monthsOverflow | Indicates if months should be calculated with overflow. | from Options |
staticprotectedbool | $yearsOverflow | Indicates if years should be calculated with overflow. | from Options |
staticprotectedbool | $strictModeEnabled | Indicates if the strict mode is in use. | from Options |
staticprotectedstring|callable|null | $formatFunction | Function to call instead of format. | from Options |
staticprotectedstring|callable|null | $createFromFormatFunction | Function to call instead of createFromFormat. | from Options |
staticprotectedstring|callable|null | $parseFunction | Function to call instead of parse. | from Options |
protectedbool|null | $localMonthsOverflow | Indicates if months should be calculated with overflow. | from Options |
protectedbool|null | $localYearsOverflow | Indicates if years should be calculated with overflow. | from Options |
protectedbool|null | $localStrictModeEnabled | Indicates if the strict mode is in use. | from Options |
protectedbool|null | $localHumanDiffOptions | Options for diffForHumans and forHumans methods. | from Options |
protectedstring|null | $localToStringFormat | Format to use on string cast. | from Options |
protectedstring|null | $localSerializer | Format to use on JSON serialization. | from Options |
protectedarray|null | $localMacros | Instance-specific macros. | from Options |
protectedarray|null | $localGenericMacros | Instance-specific generic macros. | from Options |
protectedstring|callable|null | $localFormatFunction | Function to call instead of format. | from Options |
staticprotectedarray|null | $cascadeFactors | ||
staticprotectedarray | $formats | ||
staticprotectedarray | $macros | The registered macros. | |
protectedmixed | $tzName | Timezone handler for settings() method. | |
int | $years | Total years of the current interval. | |
int | $months | Total months of the current interval. | |
int | $weeks | Total weeks of the current interval calculated from the days. | |
int | $dayz | Total days of the current interval (weeks * 7 + days). | |
int | $hours | Total hours of the current interval. | |
int | $minutes | Total minutes of the current interval. | |
int | $seconds | Total seconds of the current interval. | |
int | $microseconds | Total microseconds of the current interval. | |
int | $milliseconds | Total microseconds of the current interval. | |
int | $microExcludeMilli | Remaining microseconds without the milliseconds. | |
int | $dayzExcludeWeeks | Total days remaining in the final week of the current instance (days % 7). | |
int | $daysExcludeWeeks | alias of dayzExcludeWeeks |
Methods
Take a date and apply either the step if set, or the current interval else.
Register macros from a mixin object.
Stack a Carbon context from inside calls of self::this() and execute a given action.
Return the current context from inside a macro callee or a null if static.
Return the current context from inside a macro callee or a new one if static.
Return default humanDiff() options (merged flags as integer).
Get the default translator instance in use.
Set the default translator instance to use.
Return true if the current instance has its own translator.
Get the translator of the current instance or the default if none set.
Set the translator for the current instance.
Returns raw translation message for a given key.
Returns raw translation message for a given key.
Translate using translation string or callback available.
Translate using translation string or callback available.
Returns the alternative number for a given integer if available in the current locale.
Translate a time string from a locale to an other.
Translate a time string from the current locale ($date->locale()
) to an other.
Get/set the locale for the current instance.
Set the current translator locale and indicate if the source locale file exists.
Set the current locale to the given, execute the passed function, reset the locale to previous one, then return the result of the closure (or null if the closure was void).
Returns true if the given locale is internally supported and has short-units support.
Returns true if the given locale is internally supported and has diff syntax support (ago, from now, before, after).
Returns true if the given locale is internally supported and has words for 1-day diff (just now, yesterday, tomorrow).
Returns true if the given locale is internally supported and has words for 2-days diff (before yesterday, after tomorrow).
Returns true if the given locale is internally supported and has period syntax support (X times, every X, from X, to X).
Returns the list of internally available locales and already loaded custom locales.
Returns list of Language object for each available locale. This object allow you to get the ISO name, native name, region and variant of the locale.
Initialize the default translator instance if necessary.
Get the locale of a given translator.
Throw an error if passed object is not LocaleAwareInterface.
Returns true if the strict mode is globally in use, false else.
Get the month overflow global behavior (can be overridden in specific instances).
Get the month overflow global behavior (can be overridden in specific instances).
Mapping of units and factors for cascading.
Set default cascading factors for ->cascade() method.
Create a new CarbonInterval instance.
Returns the factor for a given source-to-target couple.
Returns the factor for a given source-to-target couple if set, else try to find the appropriate constant as the factor, such as Carbon::DAYS_PER_WEEK.
Returns current config for days per week.
Returns current config for hours per day.
Returns current config for minutes per hour.
Returns current config for seconds per minute.
Returns current config for microseconds per second.
Returns current config for microseconds per second.
Create a new CarbonInterval instance from specific values.
Parse a string into a new CarbonInterval object according to the specified format.
Get a copy of the instance.
Get a copy of the instance.
Provide static helpers to create instances. Allows CarbonInterval::years(3).
Creates a CarbonInterval from string.
Creates a CarbonInterval from string using a different locale.
Cast the current instance into the given class.
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.
Make a CarbonInterval instance from given variable if possible.
No description
No description
No description
Get a part of the CarbonInterval object.
Get a part of the CarbonInterval object.
Set a part of the CarbonInterval object.
Set a part of the CarbonInterval object.
Allow setting of weeks and days to be cumulative.
Returns true if the interval is empty for each unit.
Register a custom macro.
Check if macro is registered.
Call given macro.
Allow fluent calls on the setters.
No description
No description
No description
Returns interval values as an array where key are the unit names and values the counts.
Returns interval non-zero values as an array where key are the unit names and values the counts.
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.
Get the current interval in a human readable format in the current locale.
Format the instance as a string using the forHumans() function.
Return native DateInterval PHP object matching the current instance.
Invert the interval.
No description
Subtract the passed interval to the current instance.
Subtract the passed interval to the current instance.
Add given parameters to the current interval.
Add given parameters to the current interval.
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.
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.
Multiply and cascade current instance by a given factor.
Divide and cascade current instance by a given divider.
Get the interval_spec string of a date interval.
Get the interval_spec string.
Convert overflowed values into bigger units.
No description
No description
Get amount of given unit equivalent to the interval.
Determines if the instance is not equal to another
Determines if the instance is greater (longer) than another
Determines if the instance is greater (longer) than another
Determines if the instance is greater (longer) than or equal to another
Determines if the instance is greater (longer) than or equal to another
Determines if the instance is less (shorter) than another
Determines if the instance is less (shorter) than another
Determines if the instance is less (shorter) than or equal to another
Determines if the instance is less (shorter) than or equal to another
Determines if the instance is between two others.
Determines if the instance is between two others, bounds excluded.
Determines if the instance is between two others, bounds excluded.
Determines if the instance is between two others
Round the current instance at the given unit with given precision if specified and the given function.
Truncate the current instance at the given unit with given precision if specified.
Ceil the current instance at the given unit with given precision if specified.
Round the current instance second with given precision if specified.
Round the current instance second with given precision if specified.
Ceil the current instance second with given precision if specified.
Details
inIntervalRoundingat line23
protected
callRoundMethod(string$method,array$parameters)
inIntervalRoundingat line38
protected
roundWith($precision,$function)
inIntervalStepat line35
Closure
getStep()
Get the dynamic step in use.
inIntervalStepat line47
setStep(Closure|null$step)
Set a step to apply instead of a fixed interval to get the new date.
Or pass null to switch to fixed interval.
inIntervalStepat line62
CarbonInterface
convertDate(DateTimeInterface$dateTime,bool$negated =false)
Take a date and apply either the step if set, or the current interval else.
The interval/step is applied negatively (typically subtraction instead of addition) if $negated is true.
at line1292
staticvoid
mixin(object|string$mixin)
Register macros from a mixin object.
inMixinat line151
staticprotectedmixed
bindMacroContext(Mixin|null$context,callable$callable)
Stack a Carbon context from inside calls of self::this() and execute a given action.
inMixinat line177
staticprotectedMixin|null
context()
Return the current context from inside a macro callee or a null if static.
at line681
staticprotectedCarbonInterval
this()
Return the current context from inside a macro callee or a new one if static.
inLocalizationat line70
static
setHumanDiffOptions(int$humanDiffOptions)deprecated
deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method.
inLocalizationat line82
static
enableHumanDiffOption(int$humanDiffOption)deprecated
deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method.
inLocalizationat line94
static
disableHumanDiffOption(int$humanDiffOption)deprecated
deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method.
inLocalizationat line104
staticint
getHumanDiffOptions()
Return default humanDiff() options (merged flags as integer).
inLocalizationat line114
staticTranslatorInterface
getTranslator()
Get the default translator instance in use.
inLocalizationat line126
staticvoid
setTranslator(TranslatorInterface$translator)
Set the default translator instance to use.
inLocalizationat line136
bool
hasLocalTranslator()
Return true if the current instance has its own translator.
inLocalizationat line146
TranslatorInterface
getLocalTranslator()
Get the translator of the current instance or the default if none set.
inLocalizationat line158
$this
setLocalTranslator(TranslatorInterface$translator)
Set the translator for the current instance.
inLocalizationat line175
staticstring
getTranslationMessageWith(TranslatorInterface$translator,string$key,string|null$locale =null,string|null$default =null)
Returns raw translation message for a given key.
inLocalizationat line203
string
getTranslationMessage(string$key,string|null$locale =null,string|null$default =null,TranslatorInterface$translator =null)
Returns raw translation message for a given key.
inLocalizationat line218
staticstring
translateWith(TranslatorInterface$translator,string$key,array$parameters =[],null$number =null)
Translate using translation string or callback available.
inLocalizationat line252
string
translate(string$key,array$parameters =[],string|int|float|null$number =null,TranslatorInterface|null$translator =null,bool$altNumbers =false)
Translate using translation string or callback available.
inLocalizationat line270
string
translateNumber(int$number)
Returns the alternative number for a given integer if available in the current locale.
inLocalizationat line329
staticstring
translateTimeString(string$timeString,string|null$from =null,string|null$to =null,int$mode =CarbonInterface::TRANSLATE_ALL)
Translate a time string from a locale to an other.
inLocalizationat line425
string
translateTimeStringTo(string$timeString,string|null$to =null)
Translate a time string from the current locale ($date->locale()
) to an other.
inLocalizationat line438
$this|string
locale(string$locale =null,string...$fallbackLocales)
Get/set the locale for the current instance.
inLocalizationat line470
staticstring
getLocale()
Get the current translator locale.
inLocalizationat line483
staticbool
setLocale(string$locale)
Set the current translator locale and indicate if the source locale file exists.
Pass 'auto' as locale to use closest language from the current LC_TIME locale.
inLocalizationat line495
static
setFallbackLocale(string$locale)
Set the fallback locale.
inLocalizationat line520
staticstring|null
getFallbackLocale()
Get the fallback locale.
inLocalizationat line540
staticmixed
executeWithLocale(string$locale,callable$func)
Set the current locale to the given, execute the passed function, reset the locale to previous one, then return the result of the closure (or null if the closure was void).
inLocalizationat line557
staticbool
localeHasShortUnits(string$locale)
Returns true if the given locale is internally supported and has short-units support.
Support is considered enabled if either year, day or hour has a short variant translated.
inLocalizationat line578
staticbool
localeHasDiffSyntax(string$locale)
Returns true if the given locale is internally supported and has diff syntax support (ago, from now, before, after).
Support is considered enabled if the 4 sentences are translated in the given locale.
inLocalizationat line609
staticbool
localeHasDiffOneDayWords(string$locale)
Returns true if the given locale is internally supported and has words for 1-day diff (just now, yesterday, tomorrow).
Support is considered enabled if the 3 words are translated in the given locale.
inLocalizationat line627
staticbool
localeHasDiffTwoDayWords(string$locale)
Returns true if the given locale is internally supported and has words for 2-days diff (before yesterday, after tomorrow).
Support is considered enabled if the 2 words are translated in the given locale.
inLocalizationat line644
staticbool
localeHasPeriodSyntax(string$locale)
Returns true if the given locale is internally supported and has period syntax support (X times, every X, from X, to X).
Support is considered enabled if the 4 sentences are translated in the given locale.
inLocalizationat line661
staticarray
getAvailableLocales()
Returns the list of internally available locales and already loaded custom locales.
(It will ignore custom translator dynamic loading.)
inLocalizationat line676
staticLanguage[]
getAvailableLocalesInfo()
Returns list of Language object for each available locale. This object allow you to get the ISO name, native name, region and variant of the locale.
inLocalizationat line691
staticprotectedTranslatorInterface
translator()
Initialize the default translator instance if necessary.
inLocalizationat line710
protectedstring|null
getTranslatorLocale(null$translator =null)
Get the locale of a given translator.
If null or omitted, current local translator is used. If no local translator is in use, current global translator is used.
inLocalizationat line728
staticprotectedLocaleAwareInterface|null
getLocaleAwareTranslator(LocaleAwareInterface|null$translator =null)
Throw an error if passed object is not LocaleAwareInterface.
inOptionsat line246
static
useStrictMode(bool$strictModeEnabled =true)deprecated
deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method.
inOptionsat line257
staticbool
isStrictModeEnabled()
Returns true if the strict mode is globally in use, false else.
(It can be overridden in specific instances.)
inOptionsat line275
staticvoid
useMonthsOverflow(bool$monthsOverflow =true)deprecated
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).
inOptionsat line291
staticvoid
resetMonthsOverflow()deprecated
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).
inOptionsat line301
staticbool
shouldOverflowMonths()
Get the month overflow global behavior (can be overridden in specific instances).
inOptionsat line319
staticvoid
useYearsOverflow(bool$yearsOverflow =true)deprecated
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).
inOptionsat line335
staticvoid
resetYearsOverflow()deprecated
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).
inOptionsat line345
staticbool
shouldOverflowYears()
Get the month overflow global behavior (can be overridden in specific instances).
inOptionsat line367
$this|Options
settings(array$settings)
Set specific options.
- strictMode: true|false|null
- monthOverflow: true|false|null
- yearOverflow: true|false|null
- humanDiffOptions: int|null
- toStringFormat: string|Closure|null
- toJsonFormat: string|Closure|null
- locale: string|null
- timezone: \DateTimeZone|string|int|null
- macros: array|null
- genericMacros: array|null
inOptionsat line405
array
getSettings()
Returns current local settings.
inOptionsat line438
array
__debugInfo()
Show truthy properties on var_dump().
inOptionsat line455
protected
addExtraDebugInfos($infos)
at line281
CarbonInterval
shiftTimezone(DateTimeZone|string$tzName)
at line265
CarbonInterval
setTimezone(DateTimeZone|string$tzName)
Set the instance's timezone from a string or object.
at line295
staticarray
getCascadeFactors()
Mapping of units and factors for cascading.
Should only be modified by changing the factors or referenced constants.
at line334
static
setCascadeFactors(array$cascadeFactors)
Set default cascading factors for ->cascade() method.
at line358
__construct(Closure|DateInterval|string|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)
Create a new CarbonInterval instance.
at line415
staticint|float|null
getFactor(string$source,string$target)
Returns the factor for a given source-to-target couple.
at line443
staticint|float|null
getFactorWithDefault(string$source,string$target)
Returns the factor for a given source-to-target couple if set, else try to find the appropriate constant as the factor, such as Carbon::DAYS_PER_WEEK.
at line470
staticint|float
getDaysPerWeek()
Returns current config for days per week.
at line480
staticint|float
getHoursPerDay()
Returns current config for hours per day.
at line490
staticint|float
getMinutesPerHour()
Returns current config for minutes per hour.
at line500
staticint|float
getSecondsPerMinute()
Returns current config for seconds per minute.
at line510
staticint|float
getMillisecondsPerSecond()
Returns current config for microseconds per second.
at line520
staticint|float
getMicrosecondsPerMillisecond()
Returns current config for microseconds per second.
at line544
staticCarbonInterval
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)
Create a new CarbonInterval instance from specific values.
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().
at line564
staticCarbonInterval
createFromFormat(string$format,string|null$interval)
Parse a string into a new CarbonInterval object according to the specified format.
at line621
CarbonInterval
copy()
Get a copy of the instance.
at line635
CarbonInterval
clone()
Get a copy of the instance.
at line651
staticCarbonInterval|null
__callStatic(string$method,array$parameters)
Provide static helpers to create instances. Allows CarbonInterval::years(3).
Note: This is done using the magic method to allow static and instance methods to have the same names.
at line712
staticCarbonInterval
fromString(string$intervalDefinition)
Creates a CarbonInterval from string.
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)
at line880
staticCarbonInterval
parseFromLocale(string$interval,string|null$locale =null)
Creates a CarbonInterval from string using a different locale.
at line932
DateInterval
cast(string$className)
Cast the current instance into the given class.
at line946
staticCarbonInterval
instance(DateInterval$interval)
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.
at line962
staticCarbonInterval|null
make(mixed|int|DateInterval|string|Closure|null$interval,string|null$unit =null)
Make a CarbonInterval instance from given variable if possible.
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.
at line983
staticprotected
makeFromString(string$interval)
at line1001
protected
resolveInterval($interval)
at line1020
static
createFromDateString($time)
at line1047
int|float|string
get(string$name)
Get a part of the CarbonInterval object.
at line1107
int|float|string
__get(string$name)
Get a part of the CarbonInterval object.
at line1122
$this
set(string|array$name,int$value =null)
Set a part of the CarbonInterval object.
at line1201
__set(string$name,int$value)
Set a part of the CarbonInterval object.
at line1214
CarbonInterval
weeksAndDays(int$weeks,int$days)
Allow setting of weeks and days to be cumulative.
at line1226
bool
isEmpty()
Returns true if the interval is empty for each unit.
at line1254
staticvoid
macro(string$name,object|callable$macro)
Register a custom macro.
at line1304
staticbool
hasMacro(string$name)
Check if macro is registered.
at line1317
protectedmixed
callMacro(string$name,array$parameters)
Call given macro.
at line1343
CarbonInterval
__call(string$method,array$parameters)
Allow fluent calls on the setters.
.. CarbonInterval::years(3)->months(5)->day().
Note: This is done using the magic method to allow static and instance methods to have the same names.
at line1372
protected
getForHumansInitialVariables($syntax,$short)
at line1403
protectedarray
getForHumansParameters(mixed$syntax =null,mixed$short =false,mixed$parts =-1,mixed$options =null)
at line1479
staticprotected
getRoundingMethodFromOptions(int$options)
at line1501
int[]
toArray()
Returns interval values as an array where key are the unit names and values the counts.
at line1520
int[]
getNonZeroValues()
Returns interval non-zero values as an array where key are the unit names and values the counts.
at line1531
int[]
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.
at line1607
string
forHumans(int|array$syntax =null,bool$short =false,int$parts =-1,int$options =null)
Get the current interval in a human readable format in the current locale.
at line1822
string
__toString()
Format the instance as a string using the forHumans() function.
at line1847
DateInterval
toDateInterval()
Return native DateInterval PHP object matching the current instance.
at line1859
CarbonPeriod
toPeriod(DateTimeInterface|string|int...$params)
Convert the interval to a CarbonPeriod.
at line1880
$this
invert(bool|int$inverted =null)
Invert the interval.
at line1887
protected
solveNegativeInterval()
at line1911
$this
add(string|DateInterval$unit,int|float$value =1)
Add the passed interval to the current instance.
at line1954
$this
sub(string|DateInterval$unit,int|float$value =1)
Subtract the passed interval to the current instance.
at line1971
$this
subtract(string|DateInterval$unit,int|float$value =1)
Subtract the passed interval to the current instance.
at line1990
$this
plus(int$years =0,int$months =0,int|float$weeks =0,int|float$days =0,int|float$hours =0,int|float$minutes =0,int|float$seconds =0,int|float$microseconds =0)
Add given parameters to the current interval.
at line2020
$this
minus(int$years =0,int$months =0,int|float$weeks =0,int|float$days =0,int|float$hours =0,int|float$minutes =0,int|float$seconds =0,int|float$microseconds =0)
Add given parameters to the current interval.
at line2051
$this
times(float|int$factor)
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.
Use times() when you want a fast and approximated calculation that does not cascade units.
For a precise and cascaded calculation,
at line2084
$this
shares(float|int$divider)
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.
Use shares() when you want a fast and approximated calculation that does not cascade units.
For a precise and cascaded calculation,
at line2089
protected
copyProperties(CarbonInterval$interval,$ignoreSign =false)
at line2113
$this
multiply(float|int$factor)
Multiply and cascade current instance by a given factor.
at line2141
$this
divide(float|int$divider)
Divide and cascade current instance by a given divider.
at line2153
staticstring
getDateIntervalSpec(DateInterval$interval,bool$microseconds =false)
Get the interval_spec string of a date interval.
at line2193
string
spec(bool$microseconds =false)
Get the interval_spec string.
at line2206
staticint
compareDateIntervals(DateInterval$first,DateInterval$second)
Comparing 2 date intervals.
at line2229
int
compare(DateInterval$interval)
Comparing with passed interval.
at line2313
$this
cascade()
Convert overflowed values into bigger units.
at line2318
hasNegativeValues()
at line2329
hasPositiveValues()
at line2349
float
total(string$unit)
Get amount of given unit equivalent to the interval.
at line2446
bool
eq(CarbonInterval|DateInterval|mixed$interval)
Determines if the instance is equal to another
at line2458
bool
equalTo(CarbonInterval|DateInterval|mixed$interval)
Determines if the instance is equal to another
at line2474
bool
ne(CarbonInterval|DateInterval|mixed$interval)
Determines if the instance is not equal to another
at line2486
bool
notEqualTo(CarbonInterval|DateInterval|mixed$interval)
Determines if the instance is not equal to another
at line2500
bool
gt(CarbonInterval|DateInterval|mixed$interval)
Determines if the instance is greater (longer) than another
at line2512
bool
greaterThan(CarbonInterval|DateInterval|mixed$interval)
Determines if the instance is greater (longer) than another
at line2528
bool
gte(CarbonInterval|DateInterval|mixed$interval)
Determines if the instance is greater (longer) than or equal to another
at line2540
bool
greaterThanOrEqualTo(CarbonInterval|DateInterval|mixed$interval)
Determines if the instance is greater (longer) than or equal to another
at line2554
bool
lt(CarbonInterval|DateInterval|mixed$interval)
Determines if the instance is less (shorter) than another
at line2566
bool
lessThan(CarbonInterval|DateInterval|mixed$interval)
Determines if the instance is less (shorter) than another
at line2582
bool
lte(CarbonInterval|DateInterval|mixed$interval)
Determines if the instance is less (shorter) than or equal to another
at line2594
bool
lessThanOrEqualTo(CarbonInterval|DateInterval|mixed$interval)
Determines if the instance is less (shorter) than or equal to another
at line2620
bool
between(CarbonInterval|DateInterval|mixed$interval1,CarbonInterval|DateInterval|mixed$interval2,bool$equal =true)
Determines if the instance is between two others.
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.
at line2642
bool
betweenIncluded(CarbonInterval|DateInterval|mixed$interval1,CarbonInterval|DateInterval|mixed$interval2)
Determines if the instance is between two others, bounds excluded.
at line2662
bool
betweenExcluded(CarbonInterval|DateInterval|mixed$interval1,CarbonInterval|DateInterval|mixed$interval2)
Determines if the instance is between two others, bounds excluded.
at line2684
bool
isBetween(CarbonInterval|DateInterval|mixed$interval1,CarbonInterval|DateInterval|mixed$interval2,bool$equal =true)
Determines if the instance is between two others
at line2700
$this
roundUnit(string$unit,float|int|string|DateInterval|null$precision =1,string$function ='round')
Round the current instance at the given unit with given precision if specified and the given function.
at line2730
$this
floorUnit(string$unit,float|int|string|DateInterval|null$precision =1)
Truncate the current instance at the given unit with given precision if specified.
at line2745
$this
ceilUnit(string$unit,float|int|string|DateInterval|null$precision =1)
Ceil the current instance at the given unit with given precision if specified.
at line2760
$this
round(float|int|string|DateInterval|null$precision =1,string$function ='round')
Round the current instance second with given precision if specified.
at line2774
$this
floor(float|int|string|DateInterval|null$precision =1)
Round the current instance second with given precision if specified.
at line2788
$this
ceil(float|int|string|DateInterval|null$precision =1)
Ceil the current instance second with given precision if specified.