Pionia Core

CarbonPeriod extends DatePeriodBase
in package
implements Countable, JsonSerializable Uses LocalFactory, IntervalRounding, Mixin, Options, ToStringFormat

Substitution of DatePeriod with some modifications and many more features.

Tags
mixin

DeprecatedPeriodProperties

SuppressWarnings

(PHPMD.TooManyFields)

SuppressWarnings

(PHPMD.CamelCasePropertyName)

SuppressWarnings

(PHPMD.CouplingBetweenObjects)

Table of Contents

Interfaces

Countable
JsonSerializable

Constants

END_DATE_FILTER  = [self::class, 'filterEndDate']
Built-in filter for limit to an end.
END_ITERATION  = [self::class, 'endIteration']
Special value which can be returned by filters to end iteration. Also a filter.
END_MAX_ATTEMPTS  = 10000
Number of maximum attempts before giving up on finding end date.
EXCLUDE_END_DATE  = 8
Exclude end date from iteration.
IMMUTABLE  = 4
Yield CarbonImmutable instances.
NEXT_MAX_ATTEMPTS  = 1000
Number of maximum attempts before giving up on finding next valid date.
RECURRENCES_FILTER  = [self::class, 'filterRecurrences']
Built-in filter for limit by recurrences.
DEFAULT_DATE_CLASS  = \Carbon\Carbon::class
Default date class of iteration items.

Properties

$carbonCurrent  : CarbonInterface|null
Current date. May temporarily hold unaccepted value when looking for a next valid date.
$carbonRecurrences  : int|float|null
Limit for number of recurrences. Applied via a filter.
$constructed  : bool
True once __construct is finished.
$dateClass  : string
Date class of iteration items.
$dateInterval  : CarbonInterval|null
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.
$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  : int|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|callable|null
Format to use on JSON serialization.
$localStrictModeEnabled  : bool|null
Indicates if the strict mode is in use.
$localToStringFormat  : string|callable|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.
$options  : int|null
Iteration options.
$startDate  : CarbonInterface|null
Period start date. Applied on rewind. Always present, now by default.
$timezone  : DateTimeZone|null
Timezone of current date. Taken from the start date.
$timezoneSetting  : DateTimeZone|string|int|null
Timezone handler for settings() method.
$validationResult  : array<string|int, mixed>|string|bool|null
The cached validation result for current date.
$clock  : WrapperClock|null
The clock that generated the current instance (or FactoryImmutable::getDefaultInstance() if none)

Methods

__call()  : mixed
Add aliases for setters.
__callStatic()  : mixed
Provide static proxy for instance aliases.
__construct()  : mixed
CarbonPeriod constructor.
__debugInfo()  : array<string|int, mixed>
__get()  : bool|CarbonInterface|CarbonInterval|int|null
Get a property allowing both `DatePeriod` snakeCase and camelCase names.
__isset()  : bool
Check if an attribute exists on the object
__toString()  : string
Convert the date period into a string.
addFilter()  : static
Add a filter to the stack.
between()  : static
calculateEnd()  : CarbonInterface
Returns the end is set, else calculated from start and recurrences.
cast()  : DatePeriod|object
Cast the current instance into the given class.
ceil()  : static
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()  : static
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()  : static
day()  : static
days()  : static
dayz()  : static
each()  : static
end()  : static|CarbonInterface
endsAfter()  : bool
Determines if the end date is after another 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 another 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()  : static
excludeEndDate()  : static
Toggle EXCLUDE_END_DATE option.
excludeStartDate()  : static
Toggle EXCLUDE_START_DATE option.
filter()  : static
filters()  : static|array<string|int, mixed>
first()  : CarbonInterface|null
Return the first date in the date period.
floor()  : static
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()  : static
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()  : void
Execute a given function on each date of the period.
get()  : bool|CarbonInterface|CarbonInterval|int|null
Get a property allowing both `DatePeriod` snakeCase and camelCase names.
getClock()  : WrapperClock|null
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.
getIterator()  : Generator
getOptions()  : int
Get the period options.
getRecurrences()  : int|float|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()  : static
hours()  : static
instance()  : static
Create a new instance from a DatePeriod or CarbonPeriod object.
interval()  : static|CarbonInterval
invert()  : static
invertDateInterval()  : static
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.
isUnfilteredAndEndLess()  : bool
Return `true` if the period has no custom filter and is guaranteed to be endless.
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.
microsecond()  : static
microseconds()  : static
millisecond()  : static
milliseconds()  : static
minute()  : static
minutes()  : static
mixin()  : void
Register macros from a mixin object.
month()  : static
months()  : static
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()  : static|int|null
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()  : static
prependFilter()  : static
Prepend a filter to the stack.
push()  : static
recurrences()  : static
removeFilter()  : static
Remove a filter by instance or name.
resetDateInterval()  : static
Reset the date interval to the default value.
resetFilters()  : static
Reset filters stack.
resetToStringFormat()  : void
Reset the format used to the default when type juggling a Carbon instance to a string
rewind()  : void
Rewind to the start date.
round()  : static
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()  : static
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()  : static
seconds()  : static
setDateClass()  : static
Set the iteration item class.
setDateInterval()  : static
Change the period date interval.
setDates()  : static
Set start and end date.
setEndDate()  : static
Change the period end date.
setFilters()  : static
Set filters stack.
setOptions()  : static
Change the period options.
setRecurrences()  : static
Add a recurrences filter (set maximum number of recurrences).
setStartDate()  : static
Change the period start date.
setTimezone()  : static
Set the instance's timezone from a string or object and apply it to start/end.
settings()  : $this|static
Set specific options.
setToStringFormat()  : void
shiftTimezone()  : static
Set the instance's timezone from a string or object and add/subtract the offset difference to start/end.
since()  : static
sinceNow()  : static
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()  : static|CarbonInterface
startsAfter()  : bool
Determines if the start date is after another 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 another given date.
startsBeforeOrAt()  : bool
Determines if the start date is before or the same as a given date.
step()  : static
stepBy()  : static
times()  : static
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()  : static
toggleOptions()  : static
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()  : static
untilNow()  : static
valid()  : bool
Check if the current position is valid.
week()  : static
weeks()  : static
year()  : static
years()  : static
addExtraDebugInfos()  : void
addMissingParts()  : string
Add missing parts of the target date from the source date.
bindMacroContext()  : mixed
Stack a Carbon context from inside calls of self::this() and execute a given action.
callMacro()  : mixed
Call given macro.
callRoundMethod()  : static|null
checkFilters()  : bool|static::END_ITERATION
Check whether current value and key pass all the filters.
context()  : static|null
Return the current context from inside a macro callee or a null if static.
copyIfImmutable()  : static
Prepare the instance to be set (self if mutable to be mutated, copy if immutable to generate a new instance).
createFilterTuple()  : array<string|int, mixed>
Create a filter tuple from raw parameters.
endIteration()  : static::END_ITERATION
End iteration filter callback.
filterEndDate()  : bool|static::END_ITERATION
End date filter callback.
filterRecurrences()  : bool|callable
Recurrences filter callback (limits number of recurrences).
getGetter()  : callable|null
Get the getter for a property allowing both `DatePeriod` snakeCase and camelCase names.
handleChangedParameters()  : void
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.
isLocalStrictModeEnabled()  : bool
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()  : self
Resolve passed arguments or DatePeriod to a CarbonPeriod object.
roundWith()  : static|null
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|static::END_ITERATION
Validate current date and stop iteration when necessary.
configureTimezone()  : array<string|int, mixed>
getAnonymousClassCodeForTrait()  : string
getEndFromRecurrences()  : CarbonInterface|null
getFactory()  : Factory
getMixableMethods()  : Generator
initLocalFactory()  : void
isInfiniteDate()  : bool
iterateUntilEnd()  : CarbonInterface|null
loadMixinClass()  : void
loadMixinTrait()  : void
makeDateTime()  : DateTimeInterface|null
makeInterval()  : CarbonInterval|null
makeTimezone()  : CarbonTimeZone|null
orderCouple()  : array<string|int, mixed>
rawDate()  : DateTimeInterface|null
setDefaultParameters()  : void
setFromAssociativeArray()  : void
transmitFactory()  : T
Trigger the given action using the local factory of the object, so it will be transmitted to any object also using this trait and calling initLocalFactory() in its constructor.

Constants

END_DATE_FILTER

Built-in filter for limit to an end.

public callable END_DATE_FILTER = [self::class, 'filterEndDate']

END_ITERATION

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

public callable END_ITERATION = [self::class, 'endIteration']

END_MAX_ATTEMPTS

Number of maximum attempts before giving up on finding end date.

public int END_MAX_ATTEMPTS = 10000

EXCLUDE_END_DATE

Exclude end date from iteration.

public int EXCLUDE_END_DATE = 8

IMMUTABLE

Yield CarbonImmutable instances.

public int IMMUTABLE = 4

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 filter for limit by recurrences.

public callable RECURRENCES_FILTER = [self::class, 'filterRecurrences']

DEFAULT_DATE_CLASS

Default date class of iteration items.

protected string DEFAULT_DATE_CLASS = \Carbon\Carbon::class

Properties

$carbonCurrent

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

protected CarbonInterface|null $carbonCurrent = null

Equal to null only before the first iteration.

$carbonRecurrences

Limit for number of recurrences. Applied via a filter.

protected int|float|null $carbonRecurrences = null

$constructed

True once __construct is finished.

protected bool $constructed = false

$dateClass

Date class of iteration items.

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

$dateInterval

Underlying date interval instance. Always present, one day by default.

protected CarbonInterval|null $dateInterval = null

$endDate

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

protected CarbonInterface|null $endDate = null

$filters

The filters stack.

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

$isDefaultInterval

Whether current date interval was set by default.

protected bool $isDefaultInterval = false

$key

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

protected int $key = 0

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 int|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|callable|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|callable|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 = []

$options

Iteration options.

protected int|null $options = null

$timezone

Timezone of current date. Taken from the start date.

protected DateTimeZone|null $timezone = null

$timezoneSetting

Timezone handler for settings() method.

protected DateTimeZone|string|int|null $timezoneSetting = null

$validationResult

The cached validation result for current date.

protected array<string|int, mixed>|string|bool|null $validationResult = null

$clock

The clock that generated the current instance (or FactoryImmutable::getDefaultInstance() if none)

private WrapperClock|null $clock = null

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>

__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>

__construct()

CarbonPeriod constructor.

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

(PHPMD.ElseExpression)

throws
InvalidArgumentException

__debugInfo()

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

__isset()

Check if an attribute exists on the object

public __isset(string $name) : bool
Parameters
$name : string
Return values
bool

__toString()

Convert the date period into a string.

public __toString() : string
Return values
string

addFilter()

Add a filter to the stack.

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

(PHPMD.UnusedFormalParameter)

Return values
static

between()

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

Create instance with start and end dates or modify the start and end dates if called on an instance.

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

calculateEnd()

Returns the end is set, else calculated from start and 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|object
Parameters
$className : string

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

Return values
DatePeriod|object

ceil()

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

public ceil([DateInterval|float|int|string|null $precision = null ]) : static
Parameters
$precision : DateInterval|float|int|string|null = null
Return values
static

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[, DateInterval|float|int|string|null $precision = 1 ]) : static
Parameters
$unit : string
$precision : DateInterval|float|int|string|null = 1
Return values
static

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

contains()

Return true if the given date is between start and end.

public contains([mixed $date = null ]) : bool
Parameters
$date : mixed = null
Return values
bool

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) : static

Create instance with start and end dates or modify the start and end dates if called on an instance.

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

day()

public static day(mixed $days) : static

Alias for days().

Parameters
$days : mixed
Return values
static

days()

public static days(mixed $days) : static

Create instance specifying a number of days for date interval or replace the interval by the given a number of days if called on an instance.

Parameters
$days : mixed
Return values
static

dayz()

public static dayz(mixed $days) : static

Alias for days().

Parameters
$days : mixed
Return values
static

each()

public static each(mixed $interval) : static

Create instance with given date interval or modify the interval if called on an instance.

Parameters
$interval : mixed
Return values
static

end()

public static end(mixed $date, mixed $inclusive) : static|CarbonInterface

Create instance specifying end date or modify the end date if called on an instance.

Parameters
$date : mixed
$inclusive : mixed
Return values
static|CarbonInterface

endsAfter()

Determines if the end date is after another 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 another 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 will 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 will never be equal.

Parameters
$period : mixed
Return values
bool

every()

public static every(mixed $interval) : static

Create instance with given date interval or modify the interval if called on an instance.

Parameters
$interval : mixed
Return values
static

excludeEndDate()

Toggle EXCLUDE_END_DATE option.

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

excludeStartDate()

Toggle EXCLUDE_START_DATE option.

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

filter()

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

Create instance with filter added to the stack or append a filter if called on an instance.

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

filters()

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

Create instance with filters stack or replace the whole filters stack if called on an instance.

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

floor()

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

public floor([DateInterval|float|int|string|null $precision = null ]) : static
Parameters
$precision : DateInterval|float|int|string|null = null
Return values
static

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[, DateInterval|float|int|string|null $precision = 1 ]) : static
Parameters
$unit : string
$precision : DateInterval|float|int|string|null = 1
Return values
static

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(mixed $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 : mixed
$arguments : mixed
Return values
bool

forEach()

Execute a given function on each date of the period.

public forEach(callable $callback) : void
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";
});

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

getIterator()

public getIterator() : Generator
Return values
Generator

getOptions()

Get the period options.

public getOptions() : int
Return values
int

getRecurrences()

Get number of recurrences.

public getRecurrences() : int|float|null
Return values
int|float|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 static hour(mixed $hours) : static

Alias for hours().

Parameters
$hours : mixed
Return values
static

hours()

public static hours(mixed $hours) : static

Create instance specifying a number of hours for date interval or replace the interval by the given a number of hours if called on an instance.

Parameters
$hours : mixed
Return values
static

instance()

Create a new instance from a DatePeriod or CarbonPeriod object.

public static instance(mixed $period) : static
Parameters
$period : mixed
Return values
static

interval()

public static interval(mixed $interval) : static|CarbonInterval

Create instance with given date interval or modify the interval if called on an instance.

Parameters
$interval : mixed
Return values
static|CarbonInterval

invert()

public static invert() : static

Create instance with inverted date interval or invert the interval if called on an instance.

Return values
static

invertDateInterval()

Invert the period date interval.

public invertDateInterval() : static
Return values
static

isConsecutiveWith()

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

public isConsecutiveWith(mixed $period, mixed ...$arguments) : bool
Parameters
$period : mixed
$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(mixed $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 : mixed
$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

isUnfilteredAndEndLess()

Return `true` if the period has no custom filter and is guaranteed to be endless.

public isUnfilteredAndEndLess() : bool

Note that we can't check if a period is endless as soon as it has custom filters because filters can emit CarbonPeriod::END_ITERATION to stop the iteration in a way we can't predict without actually iterating the period.

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, callable|null $macro) : void

Pass null macro to remove it.

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

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

microsecond()

public static microsecond(mixed $microseconds) : static

Alias for microseconds().

Parameters
$microseconds : mixed
Return values
static

microseconds()

public static microseconds(mixed $microseconds) : static

Create instance specifying a number of microseconds for date interval or replace the interval by the given a number of microseconds if called on an instance.

Parameters
$microseconds : mixed
Return values
static

millisecond()

public static millisecond(mixed $milliseconds) : static

Alias for milliseconds().

Parameters
$milliseconds : mixed
Return values
static

milliseconds()

public static milliseconds(mixed $milliseconds) : static

Create instance specifying a number of milliseconds for date interval or replace the interval by the given a number of milliseconds if called on an instance.

Parameters
$milliseconds : mixed
Return values
static

minute()

public static minute(mixed $minutes) : static

Alias for minutes().

Parameters
$minutes : mixed
Return values
static

minutes()

public static minutes(mixed $minutes) : static

Create instance specifying a number of minutes for date interval or replace the interval by the given a number of minutes if called on an instance.

Parameters
$minutes : mixed
Return values
static

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

month()

public static month(mixed $months) : static

Alias for months().

Parameters
$months : mixed
Return values
static

months()

public static months(mixed $months) : static

Create instance specifying a number of months for date interval or replace the interval by the given a number of months if called on an instance.

Parameters
$months : mixed
Return values
static

ne()

Determines if the instance is not equal to another.

public ne(mixed $period) : bool

Warning: if options differ, instances will 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

notEqualTo()

Determines if the instance is not equal to another.

public notEqualTo(mixed $period) : bool

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

Parameters
$period : mixed
Return values
bool

options()

public static options(mixed $options) : static|int|null

Create instance with options or modify the options if called on an instance.

Parameters
$options : mixed
Return values
static|int|null

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) : static

Create instance with filter prepended to the stack or prepend a filter if called on an instance.

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

prependFilter()

Prepend a filter to the stack.

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

(PHPMD.UnusedFormalParameter)

Return values
static

push()

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

Alias for filter().

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

recurrences()

public static recurrences(mixed $recurrences) : static

Create instance with maximum number of recurrences or modify the number of recurrences if called on an instance.

Parameters
$recurrences : mixed
Return values
static

removeFilter()

Remove a filter by instance or name.

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

resetDateInterval()

Reset the date interval to the default value.

public resetDateInterval() : static

Difference with simply setting interval to 1-day is that P1D will not appear when calling toIso8601String() and also next adding to the interval won't include the default 1-day.

Return values
static

resetFilters()

Reset filters stack.

public resetFilters() : static
Return values
static

resetToStringFormat()

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

public static resetToStringFormat() : void

round()

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

public round([DateInterval|float|int|string|null $precision = null ][, callable|string $function = 'round' ]) : static
Parameters
$precision : DateInterval|float|int|string|null = null
$function : callable|string = 'round'
Return values
static

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[, DateInterval|float|int|string|null $precision = 1 ][, callable|string $function = 'round' ]) : static
Parameters
$unit : string
$precision : DateInterval|float|int|string|null = 1
$function : callable|string = 'round'
Return values
static

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 static second(mixed $seconds) : static

Alias for seconds().

Parameters
$seconds : mixed
Return values
static

seconds()

public static seconds(mixed $seconds) : static

Create instance specifying a number of seconds for date interval or replace the interval by the given a number of seconds if called on an instance.

Parameters
$seconds : mixed
Return values
static

setDateClass()

Set the iteration item class.

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

setDateInterval()

Change the period date interval.

public setDateInterval(DateInterval|string|int $interval[, Unit|string $unit = null ]) : static
Parameters
$interval : DateInterval|string|int
$unit : Unit|string = null

the unit of $interval if it's a number

Tags
throws
InvalidIntervalException
Return values
static

setDates()

Set start and end date.

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

setEndDate()

Change the period end date.

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

setFilters()

Set filters stack.

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

setOptions()

Change the period options.

public setOptions(int|null $options) : static
Parameters
$options : int|null
Return values
static

setRecurrences()

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

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

setStartDate()

Change the period start date.

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

setTimezone()

Set the instance's timezone from a string or object and apply it to start/end.

public setTimezone(DateTimeZone|string|int $timezone) : static
Parameters
$timezone : DateTimeZone|string|int
Return values
static

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

setToStringFormat()

public static setToStringFormat(string|Closure|null $format) : void
Parameters
$format : string|Closure|null
Tags
deprecated

To avoid conflict between different third-party libraries, static setters should not be used. You should rather let Carbon object being cast to string with DEFAULT_TO_STRING_FORMAT, and use other method or custom format passed to format() method if you need to dump another string format.

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

shiftTimezone()

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

public shiftTimezone(DateTimeZone|string|int $timezone) : static
Parameters
$timezone : DateTimeZone|string|int
Return values
static

since()

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

Alias for start().

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

sinceNow()

public static sinceNow(mixed $inclusive) : static

Create instance with start date set to now or set the start date to now if called on an instance.

Parameters
$inclusive : mixed
Return values
static

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) : static|CarbonInterface

Create instance specifying start date or modify the start date if called on an instance.

Parameters
$date : mixed
$inclusive : mixed
Return values
static|CarbonInterface

startsAfter()

Determines if the start date is after another 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 another 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

step()

public static step(mixed $interval) : static

Create instance with given date interval or modify the interval if called on an instance.

Parameters
$interval : mixed
Return values
static

stepBy()

public static stepBy(mixed $interval) : static

Create instance with given date interval or modify the interval if called on an instance.

Parameters
$interval : mixed
Return values
static

times()

public static times(mixed $recurrences) : static

Alias for recurrences().

Parameters
$recurrences : mixed
Return values
static

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) : static

Create instance with options toggled on or off, or toggle options if called on an instance.

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

toggleOptions()

Toggle given options on or off.

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

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 static until(mixed $date, mixed $inclusive) : static

Alias for end().

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

untilNow()

public static untilNow(mixed $inclusive) : static

Create instance with end date set to now or set the end date to now if called on an instance.

Parameters
$inclusive : mixed
Return values
static

valid()

Check if the current position is valid.

public valid() : bool
Return values
bool

week()

public static week(mixed $weeks) : static

Alias for weeks().

Parameters
$weeks : mixed
Return values
static

weeks()

public static weeks(mixed $weeks) : static

Create instance specifying a number of weeks for date interval or replace the interval by the given a number of weeks if called on an instance.

Parameters
$weeks : mixed
Return values
static

year()

public static year(mixed $years) : static

Alias for years().

Parameters
$years : mixed
Return values
static

years()

public static years(mixed $years) : static

Create instance specifying a number of years for date interval or replace the interval by the given a number of years if called on an instance.

Parameters
$years : mixed
Return values
static

addExtraDebugInfos()

protected addExtraDebugInfos(array<string|int, mixed> &$infos) : void
Parameters
$infos : array<string|int, mixed>

addMissingParts()

Add missing parts of the target date from the source 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(self|null $context, callable $callable) : mixed
Parameters
$context : self|null
$callable : callable

callMacro()

Call given macro.

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

callRoundMethod()

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

checkFilters()

Check whether current value and key pass all the filters.

protected checkFilters() : bool|static::END_ITERATION
Return values
bool|static::END_ITERATION

context()

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

protected static context() : static|null
Return values
static|null

copyIfImmutable()

Prepare the instance to be set (self if mutable to be mutated, copy if immutable to generate a new instance).

protected copyIfImmutable() : static
Return values
static

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() : static::END_ITERATION
Return values
static::END_ITERATION

filterRecurrences()

Recurrences filter callback (limits number of recurrences).

protected filterRecurrences(CarbonInterface $current, int $key) : bool|callable
Parameters
$current : CarbonInterface
$key : int
Tags
SuppressWarnings

(PHPMD.UnusedFormalParameter)

Return values
bool|callable

getGetter()

Get the getter for a property allowing both `DatePeriod` snakeCase and camelCase names.

protected getGetter(string $name) : callable|null
Parameters
$name : string
Return values
callable|null

handleChangedParameters()

Handle change of the parameters.

protected handleChangedParameters() : void

incrementCurrentDateUntilValid()

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

protected incrementCurrentDateUntilValid() : void
Tags
throws
RuntimeException

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|string $callable) : bool
Parameters
$callable : callable|string
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 valid parameter.

Parameters
$var : mixed
Return values
bool

isLocalStrictModeEnabled()

protected isLocalStrictModeEnabled() : bool
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) : self
Parameters
$period : mixed
$arguments : mixed
Return values
self

roundWith()

protected roundWith(DateInterval|string|float|int $precision, callable|string $function) : static|null
Parameters
$precision : DateInterval|string|float|int
$function : callable|string
Return values
static|null

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

validateCurrentDate()

Validate current date and stop iteration when necessary.

protected validateCurrentDate() : bool|static::END_ITERATION

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

Return values
bool|static::END_ITERATION

configureTimezone()

private configureTimezone(DateTimeZone $timezone, array<string|int, mixed> $sortedArguments, array<string|int, mixed> $originalArguments) : array<string|int, mixed>
Parameters
$timezone : DateTimeZone
$sortedArguments : array<string|int, mixed>
$originalArguments : array<string|int, mixed>
Return values
array<string|int, mixed>

getAnonymousClassCodeForTrait()

private static getAnonymousClassCodeForTrait(string $trait) : string
Parameters
$trait : string
Return values
string

getMixableMethods()

private static getMixableMethods(self $context) : Generator
Parameters
$context : self
Return values
Generator

isInfiniteDate()

private isInfiniteDate(mixed $date) : bool
Parameters
$date : mixed
Return values
bool

loadMixinClass()

private static loadMixinClass(object|string $mixin) : void
Parameters
$mixin : object|string
Tags
throws
ReflectionException

loadMixinTrait()

private static loadMixinTrait(string $trait) : void
Parameters
$trait : string

makeDateTime()

private makeDateTime(mixed $value) : DateTimeInterface|null
Parameters
$value : mixed
Return values
DateTimeInterface|null

orderCouple()

private orderCouple(mixed $first, mixed $second) : array<string|int, mixed>
Parameters
$first : mixed
$second : mixed
Return values
array<string|int, mixed>

rawDate()

private rawDate(mixed $date) : DateTimeInterface|null
Parameters
$date : mixed
Return values
DateTimeInterface|null

setDefaultParameters()

private static setDefaultParameters(array<string|int, mixed> &$parameters, array<string|int, mixed> $defaults) : void
Parameters
$parameters : array<string|int, mixed>
$defaults : array<string|int, mixed>

setFromAssociativeArray()

private setFromAssociativeArray(array<string|int, mixed> $parameters) : void
Parameters
$parameters : array<string|int, mixed>

transmitFactory()

Trigger the given action using the local factory of the object, so it will be transmitted to any object also using this trait and calling initLocalFactory() in its constructor.

private transmitFactory(Closure $action) : T
Parameters
$action : Closure
Tags
template

T

Return values
T

        
On this page

Search results