FileAccess Orion

CarbonPeriod
in package
implements Iterator, Countable, JsonSerializable Uses IntervalRounding, Mixin, Options

Substitution of DatePeriod with some modifications and many more features.

Interfaces, Classes, Traits and Enums

Iterator
Countable
JsonSerializable

Table of Contents

END_DATE_FILTER  = 'Carbon\\CarbonPeriod::filterEndDate'
END_ITERATION  = 'Carbon\\CarbonPeriod::endIteration'
Special value which can be returned by filters to end iteration. Also a filter.
EXCLUDE_END_DATE  = 2
EXCLUDE_START_DATE  = 1
Available options.
IMMUTABLE  = 4
NEXT_MAX_ATTEMPTS  = 1000
Number of maximum attempts before giving up on finding next valid date.
RECURRENCES_FILTER  = 'Carbon\\CarbonPeriod::filterRecurrences'
Built-in filters.
$PHPIntSize  : int
Customizable PHP_INT_SIZE override.
$createFromFormatFunction  : string|callable|null
Function to call instead of createFromFormat.
$current  : CarbonInterface
Current date. May temporarily hold unaccepted value when looking for a next valid date.
$dateClass  : string
Date class of iteration items.
$dateInterval  : CarbonInterval
Underlying date interval instance. Always present, one day by default.
$endDate  : CarbonInterface|null
Period end date. For inverted interval should be before the start date. Applied via a filter.
$filters  : array<string|int, mixed>
The filters stack.
$formatFunction  : string|callable|null
Function to call instead of format.
$isDefaultInterval  : bool
Whether current date interval was set by default.
$key  : int
Index of current date. Always sequential, even if some dates are skipped by filters.
$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.
$options  : int
Iteration options.
$parseFunction  : string|callable|null
Function to call instead of parse.
$recurrences  : int|null
Limit for number of recurrences. Applied via a filter.
$regexFormats  : array<string|int, mixed>
Format regex patterns.
$startDate  : CarbonInterface
Period start date. Applied on rewind. Always present, now by default.
$strictModeEnabled  : bool
Indicates if the strict mode is in use.
$timezone  : DateTimeZone|null
Timezone of current date. Taken from the start date.
$tzName  : mixed
Timezone handler for settings() method.
$validationResult  : bool|string|null
The cached validation result for current date.
$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.
__call()  : mixed
Add aliases for setters.
__callStatic()  : mixed
Provide static proxy for instance aliases.
__construct()  : mixed
CarbonPeriod constructor.
__debugInfo()  : array<string|int, mixed>
Show truthy properties on var_dump().
__toString()  : string
Convert the date period into a string.
addFilter()  : $this
Add a filter to the stack.
between()  : CarbonPeriod
calculateEnd()  : CarbonInterface
Returns the end is set, else calculated from start an recurrences.
cast()  : DatePeriod
Cast the current instance into the given class.
ceil()  : $this
Ceil the current instance second with given precision if specified (else period interval is used).
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
contains()  : bool
Return true if the given date is between start and end.
copy()  : static
Get a copy of the instance.
count()  : int
Count dates in the date period.
create()  : static
Create a new instance.
createFromArray()  : static
Create a new instance from an array of parameters.
createFromIso()  : static
Create CarbonPeriod from ISO 8601 string.
current()  : CarbonInterface|null
Return the current date.
dates()  : CarbonPeriod
dates()  : $this
day()  : CarbonPeriod
day()  : $this
days()  : CarbonPeriod
days()  : $this
dayz()  : CarbonPeriod
dayz()  : $this
each()  : CarbonPeriod
end()  : CarbonPeriod
end()  : $this
endsAfter()  : bool
Determines if the end date is after an other given date.
endsAfterOrAt()  : bool
Determines if the end date is after or the same as a given date.
endsAt()  : bool
Determines if the end date is the same as a given date.
endsBefore()  : bool
Determines if the end date is before an other given date.
endsBeforeOrAt()  : bool
Determines if the end date is before or the same as a given date.
eq()  : bool
Determines if the instance is equal to another.
equalTo()  : bool
Determines if the instance is equal to another.
every()  : CarbonPeriod
excludeEndDate()  : $this
Toggle EXCLUDE_END_DATE option.
excludeStartDate()  : $this
Toggle EXCLUDE_START_DATE option.
filter()  : CarbonPeriod
filter()  : $this
filters()  : CarbonPeriod
filters()  : $this
first()  : CarbonInterface|null
Return the first date in the date period.
floor()  : $this
Round the current instance second with given precision if specified (else period interval is used).
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
follows()  : bool
Return true if the current period follows a given other period (with no overlap).
forEach()  : mixed
Execute a given function on each date of the period.
getDateClass()  : string
Returns iteration item date class.
getDateInterval()  : CarbonInterval
Get the underlying date interval.
getEndDate()  : CarbonInterface|null
Get end date of the period.
getFilters()  : array<string|int, mixed>
Get filters stack.
getIncludedEndDate()  : CarbonInterface
Return the end if it's included by option, else return the end - 1 period interval.
getIncludedStartDate()  : CarbonInterface
Return the start if it's included by option, else return the start + 1 period interval.
getOptions()  : int
Get the period options.
getRecurrences()  : int|null
Get number of recurrences.
getSettings()  : array<string|int, mixed>
Returns current local settings.
getStartDate()  : CarbonInterface
Get start date of the period.
hasFilter()  : bool
Return whether given instance or name is in the filter stack.
hasMacro()  : bool
Check if macro is registered.
hour()  : CarbonPeriod
hour()  : $this
hours()  : CarbonPeriod
hours()  : $this
instance()  : static
Create a new instance from a DatePeriod or CarbonPeriod object.
interval()  : CarbonPeriod
interval()  : $this
invert()  : CarbonPeriod
invert()  : $this
invertDateInterval()  : $this
Invert the period date interval.
isConsecutiveWith()  : bool
Return true if the given period either follows or is followed by the current one.
isEnded()  : bool
Return true if end date is now or later.
isEndExcluded()  : bool
Returns true if the end date should be excluded.
isEndIncluded()  : bool
Returns true if the end date should be included.
isFollowedBy()  : bool
Return true if the given other period follows the current one (with no overlap).
isInProgress()  : bool
Return true if now is between start date (included) and end date (excluded).
isStarted()  : bool
Return true if start date is now or later.
isStartExcluded()  : bool
Returns true if the start date should be excluded.
isStartIncluded()  : bool
Returns true if the start date should be included.
isStrictModeEnabled()  : bool
Returns true if the strict mode is globally in use, false else.
jsonSerialize()  : array<string|int, CarbonInterface>
Specify data which should be serialized to JSON.
key()  : int|null
Return the current key.
last()  : CarbonInterface|null
Return the last date in the date period.
macro()  : void
Register a custom macro.
make()  : static|null
Make a CarbonPeriod instance from given variable if possible.
map()  : Generator
Execute a given function on each date of the period and yield the result of this function.
minute()  : CarbonPeriod
minute()  : $this
minutes()  : CarbonPeriod
minutes()  : $this
mixin()  : void
Register macros from a mixin object.
month()  : CarbonPeriod
month()  : $this
months()  : CarbonPeriod
months()  : $this
ne()  : bool
Determines if the instance is not equal to another.
next()  : void
Move forward to the next date.
notEqualTo()  : bool
Determines if the instance is not equal to another.
options()  : CarbonPeriod
options()  : $this
overlaps()  : bool
Returns true if the current period overlaps the given one (if 1 parameter passed) or the period between 2 dates (if 2 parameters passed).
prepend()  : CarbonPeriod
prepend()  : $this
prependFilter()  : $this
Prepend a filter to the stack.
push()  : CarbonPeriod
push()  : $this
recurrences()  : CarbonPeriod
recurrences()  : $this
removeFilter()  : $this
Remove a filter by instance or name.
resetFilters()  : $this
Reset filters stack.
resetMonthsOverflow()  : void
resetYearsOverflow()  : void
rewind()  : void
Rewind to the start date.
round()  : $this
Round the current instance second with given precision if specified (else period interval is used).
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()  : CarbonPeriod
second()  : $this
seconds()  : CarbonPeriod
seconds()  : $this
setDateClass()  : $this
Set the iteration item class.
setDateInterval()  : $this
Change the period date interval.
setDates()  : $this
Set start and end date.
setEndDate()  : $this
Change the period end date.
setFilters()  : $this
Set filters stack.
setOptions()  : $this
Change the period options.
setRecurrences()  : $this
Add a recurrences filter (set maximum number of recurrences).
setStartDate()  : $this
Change the period start date.
settings()  : $this|static
Set specific options.
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).
since()  : CarbonPeriod
since()  : $this
sinceNow()  : CarbonPeriod
sinceNow()  : $this
skip()  : bool
Skip iterations and returns iteration state (false if ended, true if still valid).
spec()  : string
Format the date period as ISO 8601.
start()  : CarbonPeriod
start()  : $this
startsAfter()  : bool
Determines if the start date is after an other given date.
startsAfterOrAt()  : bool
Determines if the start date is after or the same as a given date.
startsAt()  : bool
Determines if the start date is the same as a given date.
startsBefore()  : bool
Determines if the start date is before an other given date.
startsBeforeOrAt()  : bool
Determines if the start date is before or the same as a given date.
step()  : CarbonPeriod
stepBy()  : CarbonPeriod
times()  : CarbonPeriod
times()  : $this
toArray()  : array<string|int, CarbonInterface>
Convert the date period into an array without changing current iteration state.
toDatePeriod()  : DatePeriod
Return native DatePeriod PHP object matching the current instance.
toggle()  : CarbonPeriod
toggle()  : $this
toggleOptions()  : $this
Toggle given options on or off.
toIso8601String()  : string
Format the date period as ISO 8601.
toString()  : string
Convert the date period into a string.
until()  : CarbonPeriod
until()  : $this
untilNow()  : CarbonPeriod
untilNow()  : $this
useMonthsOverflow()  : void
useStrictMode()  : mixed
useYearsOverflow()  : void
valid()  : bool
Check if the current position is valid.
week()  : CarbonPeriod
week()  : $this
weeks()  : CarbonPeriod
weeks()  : $this
year()  : CarbonPeriod
year()  : $this
years()  : CarbonPeriod
years()  : $this
addMissingParts()  : string
Add missing parts of the target date from the soure date.
bindMacroContext()  : mixed
Stack a Carbon context from inside calls of self::this() and execute a given action.
callMacro()  : mixed
Call given macro.
callRoundMethod()  : mixed
checkFilters()  : bool|string
Check whether current value and key pass all the filters.
createFilterTuple()  : array<string|int, mixed>
Create a filter tuple from raw parameters.
endIteration()  : string
End iteration filter callback.
filterEndDate()  : bool|string
End date filter callback.
filterRecurrences()  : bool|string
Recurrences filter callback (limits number of recurrences).
handleChangedParameters()  : mixed
Handle change of the parameters.
incrementCurrentDateUntilValid()  : void
Keep incrementing the current date until a valid date is found or the iteration is ended.
intervalHasTime()  : bool
Return whether given interval contains non zero value of any time unit.
isCarbonPredicateMethod()  : bool
Return whether given callable is a string pointing to one of Carbon's is* methods and should be automatically converted to a filter callback.
isIso8601()  : bool
Return whether given variable is an ISO 8601 specification.
parseIso8601()  : array<string|int, mixed>
Parse given ISO 8601 string into an array of arguments.
prepareForReturn()  : CarbonInterface
Prepare given date to be returned to the external logic.
resolveCarbon()  : CarbonInterface
Return the Carbon instance passed through, a now instance in the same timezone if null given or parse the input if string given.
resolveCarbonPeriod()  : static
Resolve passed arguments or DatePeriod to a CarbonPeriod object.
roundWith()  : mixed
this()  : static
Return the current context from inside a macro callee or a new one if static.
updateInternalState()  : void
Update properties after removing built-in filters.
validateCurrentDate()  : bool|string
Validate current date and stop iteration when necessary.
loadMixinClass()  : mixed
loadMixinTrait()  : mixed

Constants

END_DATE_FILTER

public mixed END_DATE_FILTER = 'Carbon\\CarbonPeriod::filterEndDate'

END_ITERATION

Special value which can be returned by filters to end iteration. Also a filter.

public string END_ITERATION = 'Carbon\\CarbonPeriod::endIteration'

EXCLUDE_START_DATE

Available options.

public int EXCLUDE_START_DATE = 1

NEXT_MAX_ATTEMPTS

Number of maximum attempts before giving up on finding next valid date.

public int NEXT_MAX_ATTEMPTS = 1000

RECURRENCES_FILTER

Built-in filters.

public string RECURRENCES_FILTER = 'Carbon\\CarbonPeriod::filterRecurrences'

Properties

$PHPIntSize

Customizable PHP_INT_SIZE override.

public static int $PHPIntSize = PHP_INT_SIZE

$createFromFormatFunction

Function to call instead of createFromFormat.

protected static string|callable|null $createFromFormatFunction = null

$current

Current date. May temporarily hold unaccepted value when looking for a next valid date.

protected CarbonInterface $current

Equal to null only before the first iteration.

$dateClass

Date class of iteration items.

protected string $dateClass = \Carbon\Carbon::class

$endDate

Period end date. For inverted interval should be before the start date. Applied via a filter.

protected CarbonInterface|null $endDate

$filters

The filters stack.

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

$formatFunction

Function to call instead of format.

protected static string|callable|null $formatFunction = null

$isDefaultInterval

Whether current date interval was set by default.

protected bool $isDefaultInterval

$key

Index of current date. Always sequential, even if some dates are skipped by filters.

protected int $key

Equal to null only before the first iteration.

$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

$recurrences

Limit for number of recurrences. Applied via a filter.

protected int|null $recurrences

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

$timezone

Timezone of current date. Taken from the start date.

protected DateTimeZone|null $timezone

$tzName

Timezone handler for settings() method.

protected mixed $tzName

$validationResult

The cached validation result for current date.

protected bool|string|null $validationResult

$weekendDays

Days of weekend.

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

$weekEndsAt

Last day of week.

protected static int $weekEndsAt = \Carbon\CarbonInterface::SUNDAY

$weekStartsAt

First day of week.

protected static int $weekStartsAt = \Carbon\CarbonInterface::MONDAY

$yearsOverflow

Indicates if years should be calculated with overflow.

protected static bool $yearsOverflow = true

Global setting.

Methods

__call()

Add aliases for setters.

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

CarbonPeriod::days(3)->hours(5)->invert() ->sinceNow()->until('2010-01-10') ->filter(...) ->count()

Note: We use magic method to let static and instance aliases with the same names.

Parameters
$method : string
$parameters : array<string|int, mixed>
Return values
mixed

__callStatic()

Provide static proxy for instance aliases.

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

__construct()

CarbonPeriod constructor.

public __construct(mixed ...$arguments) : mixed
Parameters
$arguments : mixed
Tags
SuppressWarnings

(PHPMD.ElseExpression)

throws
InvalidArgumentException
Return values
mixed

__debugInfo()

Show truthy properties on var_dump().

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

__toString()

Convert the date period into a string.

public __toString() : string
Return values
string

addFilter()

Add a filter to the stack.

public addFilter(callable $callback[, string $name = null ]) : $this
Parameters
$callback : callable
$name : string = null
Tags
SuppressWarnings

(PHPMD.UnusedFormalParameter)

Return values
$this

between()

public static between(mixed $start, mixed $end) : CarbonPeriod

Create instance with start and end date.

Parameters
$start : mixed
$end : mixed
Return values
CarbonPeriod

calculateEnd()

Returns the end is set, else calculated from start an recurrences.

public calculateEnd([string|null $rounding = null ]) : CarbonInterface
Parameters
$rounding : string|null = null

Optional rounding 'floor', 'ceil', 'round' using the period interval.

Return values
CarbonInterface

cast()

Cast the current instance into the given class.

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

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

Return values
DatePeriod

ceil()

Ceil the current instance second with given precision if specified (else period interval is used).

public ceil([float|int|string|DateInterval|null $precision = null ]) : $this
Parameters
$precision : float|int|string|DateInterval|null = null
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
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()

public clone() : static
Tags
alias

copy

Get a copy of the instance.

Return values
static

copy()

Get a copy of the instance.

public copy() : static
Return values
static

count()

Count dates in the date period.

public count() : int
Return values
int

create()

Create a new instance.

public static create(mixed ...$params) : static
Parameters
$params : mixed
Return values
static

createFromArray()

Create a new instance from an array of parameters.

public static createFromArray(array<string|int, mixed> $params) : static
Parameters
$params : array<string|int, mixed>
Return values
static

createFromIso()

Create CarbonPeriod from ISO 8601 string.

public static createFromIso(string $iso[, int|null $options = null ]) : static
Parameters
$iso : string
$options : int|null = null
Return values
static

dates()

public static dates(mixed $start, mixed $end) : CarbonPeriod

Create instance with start and end date.

Parameters
$start : mixed
$end : mixed
Return values
CarbonPeriod

dates()

public dates(mixed $start, mixed $end) : $this

Change the period start and end date.

Parameters
$start : mixed
$end : mixed
Return values
$this

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 date interval.

Parameters
$days : mixed
Return values
$this

dayz()

public dayz(mixed $days) : $this

Alias for days().

Parameters
$days : mixed
Return values
$this

end()

public static end(mixed $date, mixed $inclusive) : CarbonPeriod

Create instance specifying end date.

Parameters
$date : mixed
$inclusive : mixed
Return values
CarbonPeriod

end()

public end(mixed $date, mixed $inclusive) : $this

Change the period end date.

Parameters
$date : mixed
$inclusive : mixed
Return values
$this

endsAfter()

Determines if the end date is after an other given date.

public endsAfter([mixed $date = null ]) : bool

(Rather start/end are included by options is ignored.)

Parameters
$date : mixed = null
Return values
bool

endsAfterOrAt()

Determines if the end date is after or the same as a given date.

public endsAfterOrAt([mixed $date = null ]) : bool

(Rather start/end are included by options is ignored.)

Parameters
$date : mixed = null
Return values
bool

endsAt()

Determines if the end date is the same as a given date.

public endsAt([mixed $date = null ]) : bool

(Rather start/end are included by options is ignored.)

Parameters
$date : mixed = null
Return values
bool

endsBefore()

Determines if the end date is before an other given date.

public endsBefore([mixed $date = null ]) : bool

(Rather start/end are included by options is ignored.)

Parameters
$date : mixed = null
Return values
bool

endsBeforeOrAt()

Determines if the end date is before or the same as a given date.

public endsBeforeOrAt([mixed $date = null ]) : bool

(Rather start/end are included by options is ignored.)

Parameters
$date : mixed = null
Return values
bool

eq()

Determines if the instance is equal to another.

public eq(mixed $period) : bool

Warning: if options differ, instances wil never be equal.

Parameters
$period : mixed
Tags
see
equalTo()
Return values
bool

equalTo()

Determines if the instance is equal to another.

public equalTo(mixed $period) : bool

Warning: if options differ, instances wil never be equal.

Parameters
$period : mixed
Return values
bool

excludeEndDate()

Toggle EXCLUDE_END_DATE option.

public excludeEndDate([bool $state = true ]) : $this
Parameters
$state : bool = true
Return values
$this

excludeStartDate()

Toggle EXCLUDE_START_DATE option.

public excludeStartDate([bool $state = true ]) : $this
Parameters
$state : bool = true
Return values
$this

filter()

public static filter(mixed $callback, mixed $name) : CarbonPeriod

Create instance with filter added to the stack.

Parameters
$callback : mixed
$name : mixed
Return values
CarbonPeriod

filter()

public filter(mixed $callback, mixed $name) : $this

Add a filter to the stack.

Parameters
$callback : mixed
$name : mixed
Return values
$this

filters()

public static filters(array<string|int, mixed> $filters) : CarbonPeriod

Create instance with filters stack.

Parameters
$filters : array<string|int, mixed>
Return values
CarbonPeriod

filters()

public filters(array<string|int, mixed> $filters = []) : $this

Set filters stack.

Parameters
$filters = [] : array<string|int, mixed>
Return values
$this

floor()

Round the current instance second with given precision if specified (else period interval is used).

public floor([float|int|string|DateInterval|null $precision = null ]) : $this
Parameters
$precision : float|int|string|DateInterval|null = null
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
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

follows()

Return true if the current period follows a given other period (with no overlap).

public follows(CarbonPeriod|DatePeriod|string $period, mixed ...$arguments) : bool

For instance, [2019-08-01 -> 2019-08-12] follows [2019-07-29 -> 2019-07-31] Note than in this example, follows() would be false if 2019-08-01 or 2019-07-31 was excluded by options.

Parameters
$period : CarbonPeriod|DatePeriod|string
$arguments : mixed
Return values
bool

forEach()

Execute a given function on each date of the period.

public forEach(callable $callback) : mixed
Parameters
$callback : callable
Tags
example
Carbon::create('2020-11-29')->daysUntil('2020-12-24')->forEach(function (Carbon $date) {
  echo $date->diffInDays('2020-12-25')." days before Christmas!\n";
});
Return values
mixed

getDateClass()

Returns iteration item date class.

public getDateClass() : string
Return values
string

getEndDate()

Get end date of the period.

public getEndDate([string|null $rounding = null ]) : CarbonInterface|null
Parameters
$rounding : string|null = null

Optional rounding 'floor', 'ceil', 'round' using the period interval.

Return values
CarbonInterface|null

getFilters()

Get filters stack.

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

getIncludedEndDate()

Return the end if it's included by option, else return the end - 1 period interval.

public getIncludedEndDate() : CarbonInterface

Warning: if the period has no fixed end, this method will iterate the period to calculate it.

Return values
CarbonInterface

getOptions()

Get the period options.

public getOptions() : int
Return values
int

getRecurrences()

Get number of recurrences.

public getRecurrences() : int|null
Return values
int|null

getSettings()

Returns current local settings.

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

getStartDate()

Get start date of the period.

public getStartDate([string|null $rounding = null ]) : CarbonInterface
Parameters
$rounding : string|null = null

Optional rounding 'floor', 'ceil', 'round' using the period interval.

Return values
CarbonInterface

hasFilter()

Return whether given instance or name is in the filter stack.

public hasFilter(callable|string $filter) : bool
Parameters
$filter : callable|string
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 static hours(mixed $hours) : CarbonPeriod

Create instance specifying a number of hours for date interval.

Parameters
$hours : mixed
Return values
CarbonPeriod

hours()

public hours(mixed $hours) : $this

Set the hours portion of the date interval.

Parameters
$hours : mixed
Return values
$this

instance()

Create a new instance from a DatePeriod or CarbonPeriod object.

public static instance(CarbonPeriod|DatePeriod $period) : static
Parameters
$period : CarbonPeriod|DatePeriod
Return values
static

interval()

public interval(mixed $interval) : $this

Change the period date interval.

Parameters
$interval : mixed
Return values
$this

invert()

public invert() : $this

Invert the period date interval.

Return values
$this

invertDateInterval()

Invert the period date interval.

public invertDateInterval() : $this
Return values
$this

isConsecutiveWith()

Return true if the given period either follows or is followed by the current one.

public isConsecutiveWith(CarbonPeriod|DatePeriod|string $period, mixed ...$arguments) : bool
Parameters
$period : CarbonPeriod|DatePeriod|string
$arguments : mixed
Tags
see
follows()
see
isFollowedBy()
Return values
bool

isEnded()

Return true if end date is now or later.

public isEnded() : bool

(Rather start/end are included by options is ignored.)

Return values
bool

isEndExcluded()

Returns true if the end date should be excluded.

public isEndExcluded() : bool
Return values
bool

isEndIncluded()

Returns true if the end date should be included.

public isEndIncluded() : bool
Return values
bool

isFollowedBy()

Return true if the given other period follows the current one (with no overlap).

public isFollowedBy(CarbonPeriod|DatePeriod|string $period, mixed ...$arguments) : bool

For instance, [2019-07-29 -> 2019-07-31] is followed by [2019-08-01 -> 2019-08-12] Note than in this example, isFollowedBy() would be false if 2019-08-01 or 2019-07-31 was excluded by options.

Parameters
$period : CarbonPeriod|DatePeriod|string
$arguments : mixed
Return values
bool

isInProgress()

Return true if now is between start date (included) and end date (excluded).

public isInProgress() : bool

(Rather start/end are included by options is ignored.)

Return values
bool

isStarted()

Return true if start date is now or later.

public isStarted() : bool

(Rather start/end are included by options is ignored.)

Return values
bool

isStartExcluded()

Returns true if the start date should be excluded.

public isStartExcluded() : bool
Return values
bool

isStartIncluded()

Returns true if the start date should be included.

public isStartIncluded() : 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

key()

Return the current key.

public key() : int|null
Return values
int|null

macro()

Register a custom macro.

public static macro(string $name, object|callable $macro) : void
Parameters
$name : string
$macro : object|callable
Tags
example
CarbonPeriod::macro('middle', function () {
  return $this->getStartDate()->average($this->getEndDate());
});
echo CarbonPeriod::since('2011-05-12')->until('2011-06-03')->middle();
Return values
void

make()

Make a CarbonPeriod instance from given variable if possible.

public static make(mixed $var) : static|null
Parameters
$var : mixed
Return values
static|null

map()

Execute a given function on each date of the period and yield the result of this function.

public map(callable $callback) : Generator
Parameters
$callback : callable
Tags
example
$period = Carbon::create('2020-11-29')->daysUntil('2020-12-24');
echo implode("\n", iterator_to_array($period->map(function (Carbon $date) {
  return $date->diffInDays('2020-12-25').' days before Christmas!';
})));
Return values
Generator

minute()

public minute(mixed $minutes) : $this

Alias for minutes().

Parameters
$minutes : mixed
Return values
$this

minutes()

public static minutes(mixed $minutes) : CarbonPeriod

Create instance specifying a number of minutes for date interval.

Parameters
$minutes : mixed
Return values
CarbonPeriod

minutes()

public minutes(mixed $minutes) : $this

Set the minutes portion of the date 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
CarbonPeriod::mixin(new class {
  public function addDays() {
    return function ($count = 1) {
      return $this->setStartDate(
        $this->getStartDate()->addDays($count)
      )->setEndDate(
        $this->getEndDate()->addDays($count)
      );
    };
  }
  public function subDays() {
    return function ($count = 1) {
      return $this->setStartDate(
        $this->getStartDate()->subDays($count)
      )->setEndDate(
        $this->getEndDate()->subDays($count)
      );
    };
  }
});
echo CarbonPeriod::create('2000-01-01', '2000-02-01')->addDays(5)->subDays(3);
throws
ReflectionException
Return values
void

month()

public month(mixed $months) : $this

Alias for months().

Parameters
$months : mixed
Return values
$this

months()

public static months(mixed $months) : CarbonPeriod

Create instance specifying a number of months for date interval.

Parameters
$months : mixed
Return values
CarbonPeriod

months()

public months(mixed $months) : $this

Set the months portion of the date interval.

Parameters
$months : mixed
Return values
$this

ne()

Determines if the instance is not equal to another.

public ne(mixed $period) : bool

Warning: if options differ, instances wil never be equal.

Parameters
$period : mixed
Tags
see
notEqualTo()
Return values
bool

next()

Move forward to the next date.

public next() : void
Tags
throws
RuntimeException
Return values
void

notEqualTo()

Determines if the instance is not equal to another.

public notEqualTo(mixed $period) : bool

Warning: if options differ, instances wil never be equal.

Parameters
$period : mixed
Return values
bool

options()

public options(mixed $options) : $this

Change the period options.

Parameters
$options : mixed
Return values
$this

overlaps()

Returns true if the current period overlaps the given one (if 1 parameter passed) or the period between 2 dates (if 2 parameters passed).

public overlaps(CarbonPeriod|DateTimeInterface|Carbon|CarbonImmutable|string $rangeOrRangeStart[, DateTimeInterface|Carbon|CarbonImmutable|string|null $rangeEnd = null ]) : bool
Parameters
$rangeOrRangeStart : CarbonPeriod|DateTimeInterface|Carbon|CarbonImmutable|string
$rangeEnd : DateTimeInterface|Carbon|CarbonImmutable|string|null = null
Return values
bool

prepend()

public static prepend(mixed $callback, mixed $name) : CarbonPeriod

Create instance with filter prepened to the stack.

Parameters
$callback : mixed
$name : mixed
Return values
CarbonPeriod

prepend()

public prepend(mixed $callback, mixed $name) : $this

Prepend a filter to the stack.

Parameters
$callback : mixed
$name : mixed
Return values
$this

prependFilter()

Prepend a filter to the stack.

public prependFilter(callable $callback[, string $name = null ]) : $this
Parameters
$callback : callable
$name : string = null
Tags
SuppressWarnings

(PHPMD.UnusedFormalParameter)

Return values
$this

push()

public push(mixed $callback, mixed $name) : $this

Alias for filter().

Parameters
$callback : mixed
$name : mixed
Return values
$this

recurrences()

public static recurrences(mixed $recurrences) : CarbonPeriod

Create instance with maximum number of recurrences.

Parameters
$recurrences : mixed
Return values
CarbonPeriod

recurrences()

public recurrences(mixed $recurrences) : $this

Change the maximum number of recurrences.

Parameters
$recurrences : mixed
Return values
$this

removeFilter()

Remove a filter by instance or name.

public removeFilter(callable|string $filter) : $this
Parameters
$filter : callable|string
Return values
$this

resetFilters()

Reset filters stack.

public resetFilters() : $this
Return values
$this

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 (else period interval is used).

public round([float|int|string|DateInterval|null $precision = null ][, string $function = 'round' ]) : $this
Parameters
$precision : float|int|string|DateInterval|null = null
$function : string = 'round'
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'
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 static seconds(mixed $seconds) : CarbonPeriod

Create instance specifying a number of seconds for date interval.

Parameters
$seconds : mixed
Return values
CarbonPeriod

seconds()

public seconds(mixed $seconds) : $this

Set the seconds portion of the date interval.

Parameters
$seconds : mixed
Return values
$this

setDateClass()

Set the iteration item class.

public setDateClass(string $dateClass) : $this
Parameters
$dateClass : string
Return values
$this

setDateInterval()

Change the period date interval.

public setDateInterval(DateInterval|string $interval) : $this
Parameters
$interval : DateInterval|string
Tags
throws
InvalidIntervalException
Return values
$this

setDates()

Set start and end date.

public setDates(DateTime|DateTimeInterface|string $start, DateTime|DateTimeInterface|string|null $end) : $this
Parameters
$start : DateTime|DateTimeInterface|string
$end : DateTime|DateTimeInterface|string|null
Return values
$this

setEndDate()

Change the period end date.

public setEndDate(DateTime|DateTimeInterface|string|null $date[, bool|null $inclusive = null ]) : $this
Parameters
$date : DateTime|DateTimeInterface|string|null
$inclusive : bool|null = null
Tags
throws
InvalidArgumentException
Return values
$this

setFilters()

Set filters stack.

public setFilters(array<string|int, mixed> $filters) : $this
Parameters
$filters : array<string|int, mixed>
Return values
$this

setOptions()

Change the period options.

public setOptions(int|null $options) : $this
Parameters
$options : int|null
Tags
throws
InvalidArgumentException
Return values
$this

setRecurrences()

Add a recurrences filter (set maximum number of recurrences).

public setRecurrences(int|null $recurrences) : $this
Parameters
$recurrences : int|null
Tags
throws
InvalidArgumentException
Return values
$this

setStartDate()

Change the period start date.

public setStartDate(DateTime|DateTimeInterface|string $date[, bool|null $inclusive = null ]) : $this
Parameters
$date : DateTime|DateTimeInterface|string
$inclusive : bool|null = null
Tags
throws
InvalidPeriodDateException
Return values
$this

settings()

Set specific options.

public settings(array<string|int, mixed> $settings) : $this|static
  • strictMode: true|false|null
  • monthOverflow: true|false|null
  • yearOverflow: true|false|null
  • humanDiffOptions: int|null
  • toStringFormat: string|Closure|null
  • toJsonFormat: string|Closure|null
  • locale: string|null
  • timezone: \DateTimeZone|string|int|null
  • macros: array|null
  • genericMacros: array|null
Parameters
$settings : array<string|int, mixed>
Return values
$this|static

shiftTimezone()

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

public shiftTimezone(DateTimeZone|string $timezone) : static
Parameters
$timezone : 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

since()

public since(mixed $date, mixed $inclusive) : $this

Alias for start().

Parameters
$date : mixed
$inclusive : mixed
Return values
$this

sinceNow()

public sinceNow(mixed $inclusive) : $this

Change the period start date to now.

Parameters
$inclusive : mixed
Return values
$this

skip()

Skip iterations and returns iteration state (false if ended, true if still valid).

public skip([int $count = 1 ]) : bool
Parameters
$count : int = 1

steps number to skip (1 by default)

Return values
bool

spec()

Format the date period as ISO 8601.

public spec() : string
Return values
string

start()

public static start(mixed $date, mixed $inclusive) : CarbonPeriod

Create instance specifying start date.

Parameters
$date : mixed
$inclusive : mixed
Return values
CarbonPeriod

start()

public start(mixed $date, mixed $inclusive) : $this

Change the period start date.

Parameters
$date : mixed
$inclusive : mixed
Return values
$this

startsAfter()

Determines if the start date is after an other given date.

public startsAfter([mixed $date = null ]) : bool

(Rather start/end are included by options is ignored.)

Parameters
$date : mixed = null
Return values
bool

startsAfterOrAt()

Determines if the start date is after or the same as a given date.

public startsAfterOrAt([mixed $date = null ]) : bool

(Rather start/end are included by options is ignored.)

Parameters
$date : mixed = null
Return values
bool

startsAt()

Determines if the start date is the same as a given date.

public startsAt([mixed $date = null ]) : bool

(Rather start/end are included by options is ignored.)

Parameters
$date : mixed = null
Return values
bool

startsBefore()

Determines if the start date is before an other given date.

public startsBefore([mixed $date = null ]) : bool

(Rather start/end are included by options is ignored.)

Parameters
$date : mixed = null
Return values
bool

startsBeforeOrAt()

Determines if the start date is before or the same as a given date.

public startsBeforeOrAt([mixed $date = null ]) : bool

(Rather start/end are included by options is ignored.)

Parameters
$date : mixed = null
Return values
bool

times()

public times(mixed $recurrences) : $this

Alias for recurrences().

Parameters
$recurrences : mixed
Return values
$this

toDatePeriod()

Return native DatePeriod PHP object matching the current instance.

public toDatePeriod() : DatePeriod
Tags
example
var_dump(CarbonPeriod::create('2021-01-05', '2021-02-15')->toDatePeriod());
Return values
DatePeriod

toggle()

public static toggle(mixed $options, mixed $state) : CarbonPeriod

Create instance with options toggled on or off.

Parameters
$options : mixed
$state : mixed
Return values
CarbonPeriod

toggle()

public toggle(mixed $options, mixed $state) : $this

Toggle given options on or off.

Parameters
$options : mixed
$state : mixed
Return values
$this

toggleOptions()

Toggle given options on or off.

public toggleOptions(int $options[, bool|null $state = null ]) : $this
Parameters
$options : int
$state : bool|null = null
Tags
throws
InvalidArgumentException
Return values
$this

toIso8601String()

Format the date period as ISO 8601.

public toIso8601String() : string
Return values
string

toString()

Convert the date period into a string.

public toString() : string
Return values
string

until()

public until(mixed $date, mixed $inclusive) : $this

Alias for end().

Parameters
$date : mixed
$inclusive : mixed
Return values
$this

untilNow()

public untilNow(mixed $inclusive) : $this

Change the period end date to now.

Parameters
$inclusive : mixed
Return values
$this

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

valid()

Check if the current position is valid.

public valid() : bool
Return values
bool

week()

public week(mixed $weeks) : $this

Alias for weeks().

Parameters
$weeks : mixed
Return values
$this

weeks()

public static weeks(mixed $weeks) : CarbonPeriod

Create instance specifying a number of weeks for date interval.

Parameters
$weeks : mixed
Return values
CarbonPeriod

weeks()

public weeks(mixed $weeks) : $this

Set the weeks portion of the date interval.

Parameters
$weeks : mixed
Return values
$this

year()

public year(mixed $years) : $this

Alias for years().

Parameters
$years : mixed
Return values
$this

years()

public static years(mixed $years) : CarbonPeriod

Create instance specifying a number of years for date interval.

Parameters
$years : mixed
Return values
CarbonPeriod

years()

public years(mixed $years) : $this

Set the years portion of the date interval.

Parameters
$years : mixed
Return values
$this

addMissingParts()

Add missing parts of the target date from the soure date.

protected static addMissingParts(string $source, string $target) : string
Parameters
$source : string
$target : string
Return values
string

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

checkFilters()

Check whether current value and key pass all the filters.

protected checkFilters() : bool|string
Return values
bool|string

createFilterTuple()

Create a filter tuple from raw parameters.

protected createFilterTuple(array<string|int, mixed> $parameters) : array<string|int, mixed>

Will create an automatic filter callback for one of Carbon's is* methods.

Parameters
$parameters : array<string|int, mixed>
Return values
array<string|int, mixed>

endIteration()

End iteration filter callback.

protected endIteration() : string
Return values
string

filterEndDate()

End date filter callback.

protected filterEndDate(Carbon $current) : bool|string
Parameters
$current : Carbon
Return values
bool|string

filterRecurrences()

Recurrences filter callback (limits number of recurrences).

protected filterRecurrences(Carbon $current, int $key) : bool|string
Parameters
$current : Carbon
$key : int
Tags
SuppressWarnings

(PHPMD.UnusedFormalParameter)

Return values
bool|string

handleChangedParameters()

Handle change of the parameters.

protected handleChangedParameters() : mixed
Return values
mixed

incrementCurrentDateUntilValid()

Keep incrementing the current date until a valid date is found or the iteration is ended.

protected incrementCurrentDateUntilValid() : void
Tags
throws
RuntimeException
Return values
void

intervalHasTime()

Return whether given interval contains non zero value of any time unit.

protected static intervalHasTime(DateInterval $interval) : bool
Parameters
$interval : DateInterval
Return values
bool

isCarbonPredicateMethod()

Return whether given callable is a string pointing to one of Carbon's is* methods and should be automatically converted to a filter callback.

protected isCarbonPredicateMethod(callable $callable) : bool
Parameters
$callable : callable
Return values
bool

isIso8601()

Return whether given variable is an ISO 8601 specification.

protected static isIso8601(mixed $var) : bool

Note: Check is very basic, as actual validation will be done later when parsing. We just want to ensure that variable is not any other type of a valid parameter.

Parameters
$var : mixed
Return values
bool

parseIso8601()

Parse given ISO 8601 string into an array of arguments.

protected static parseIso8601(string $iso) : array<string|int, mixed>
Parameters
$iso : string
Tags
SuppressWarnings

(PHPMD.ElseExpression)

Return values
array<string|int, mixed>

resolveCarbonPeriod()

Resolve passed arguments or DatePeriod to a CarbonPeriod object.

protected resolveCarbonPeriod(mixed $period, mixed ...$arguments) : static
Parameters
$period : mixed
$arguments : mixed
Return values
static

roundWith()

protected roundWith(mixed $precision, mixed $function) : mixed
Parameters
$precision : mixed
$function : 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

updateInternalState()

Update properties after removing built-in filters.

protected updateInternalState() : void
Return values
void

validateCurrentDate()

Validate current date and stop iteration when necessary.

protected validateCurrentDate() : bool|string

Returns true when current date is valid, false if it is not, or static::END_ITERATION when iteration should be stopped.

Return values
bool|string

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

Search results