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
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
$startDate
Period start date. Applied on rewind. Always present, now by default.
protected
CarbonInterface|null
$startDate
= 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
__debugInfo()
public
__debugInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>__get()
Get a property allowing both `DatePeriod` snakeCase and camelCase names.
public
__get(string $name) : bool|CarbonInterface|CarbonInterval|int|null
Parameters
- $name : string
Return values
bool|CarbonInterface|CarbonInterval|int|null__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
stringaddFilter()
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
Return values
staticbetween()
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
staticcalculateEnd()
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
CarbonInterfacecast()
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|objectceil()
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
staticceilCenturies()
public
ceilCenturies(float $precision = 1) : $this
Ceil the current instance century with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilCentury()
public
ceilCentury(float $precision = 1) : $this
Ceil the current instance century with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilDay()
public
ceilDay(float $precision = 1) : $this
Ceil the current instance day with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilDays()
public
ceilDays(float $precision = 1) : $this
Ceil the current instance day with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilDecade()
public
ceilDecade(float $precision = 1) : $this
Ceil the current instance decade with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilDecades()
public
ceilDecades(float $precision = 1) : $this
Ceil the current instance decade with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilHour()
public
ceilHour(float $precision = 1) : $this
Ceil the current instance hour with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilHours()
public
ceilHours(float $precision = 1) : $this
Ceil the current instance hour with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilMicrosecond()
public
ceilMicrosecond(float $precision = 1) : $this
Ceil the current instance microsecond with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilMicroseconds()
public
ceilMicroseconds(float $precision = 1) : $this
Ceil the current instance microsecond with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilMillennia()
public
ceilMillennia(float $precision = 1) : $this
Ceil the current instance millennium with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilMillennium()
public
ceilMillennium(float $precision = 1) : $this
Ceil the current instance millennium with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilMillisecond()
public
ceilMillisecond(float $precision = 1) : $this
Ceil the current instance millisecond with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilMilliseconds()
public
ceilMilliseconds(float $precision = 1) : $this
Ceil the current instance millisecond with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilMinute()
public
ceilMinute(float $precision = 1) : $this
Ceil the current instance minute with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilMinutes()
public
ceilMinutes(float $precision = 1) : $this
Ceil the current instance minute with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilMonth()
public
ceilMonth(float $precision = 1) : $this
Ceil the current instance month with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilMonths()
public
ceilMonths(float $precision = 1) : $this
Ceil the current instance month with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilQuarter()
public
ceilQuarter(float $precision = 1) : $this
Ceil the current instance quarter with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilQuarters()
public
ceilQuarters(float $precision = 1) : $this
Ceil the current instance quarter with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilSecond()
public
ceilSecond(float $precision = 1) : $this
Ceil the current instance second with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilSeconds()
public
ceilSeconds(float $precision = 1) : $this
Ceil the current instance second with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilUnit()
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
staticceilWeek()
public
ceilWeek(float $precision = 1) : $this
Ceil the current instance day with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilWeeks()
public
ceilWeeks(float $precision = 1) : $this
Ceil the current instance day with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilYear()
public
ceilYear(float $precision = 1) : $this
Ceil the current instance year with given precision.
Parameters
- $precision = 1 : float
Return values
$thisceilYears()
public
ceilYears(float $precision = 1) : $this
Ceil the current instance year with given precision.
Parameters
- $precision = 1 : float
Return values
$thisclone()
public
clone() : static
Tags
Return values
staticcontains()
Return true if the given date is between start and end.
public
contains([mixed $date = null ]) : bool
Parameters
- $date : mixed = null
Return values
boolcopy()
Get a copy of the instance.
public
copy() : static
Return values
staticcount()
Count dates in the date period.
public
count() : int
Return values
intcreate()
Create a new instance.
public
static create(mixed ...$params) : static
Parameters
- $params : mixed
Return values
staticcreateFromArray()
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
staticcreateFromIso()
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
staticcurrent()
Return the current date.
public
current() : CarbonInterface|null
Return values
CarbonInterface|nulldates()
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
staticday()
public
static day(mixed $days) : static
Alias for days().
Parameters
- $days : mixed
Return values
staticdays()
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
staticdayz()
public
static dayz(mixed $days) : static
Alias for days().
Parameters
- $days : mixed
Return values
staticeach()
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
staticend()
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|CarbonInterfaceendsAfter()
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
boolendsAfterOrAt()
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
boolendsAt()
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
boolendsBefore()
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
boolendsBeforeOrAt()
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
booleq()
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
Return values
boolequalTo()
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
boolevery()
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
staticexcludeEndDate()
Toggle EXCLUDE_END_DATE option.
public
excludeEndDate([bool $state = true ]) : static
Parameters
- $state : bool = true
Return values
staticexcludeStartDate()
Toggle EXCLUDE_START_DATE option.
public
excludeStartDate([bool $state = true ]) : static
Parameters
- $state : bool = true
Return values
staticfilter()
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
staticfilters()
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>first()
Return the first date in the date period.
public
first() : CarbonInterface|null
Return values
CarbonInterface|nullfloor()
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
staticfloorCenturies()
public
floorCenturies(float $precision = 1) : $this
Truncate the current instance century with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorCentury()
public
floorCentury(float $precision = 1) : $this
Truncate the current instance century with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorDay()
public
floorDay(float $precision = 1) : $this
Truncate the current instance day with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorDays()
public
floorDays(float $precision = 1) : $this
Truncate the current instance day with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorDecade()
public
floorDecade(float $precision = 1) : $this
Truncate the current instance decade with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorDecades()
public
floorDecades(float $precision = 1) : $this
Truncate the current instance decade with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorHour()
public
floorHour(float $precision = 1) : $this
Truncate the current instance hour with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorHours()
public
floorHours(float $precision = 1) : $this
Truncate the current instance hour with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorMicrosecond()
public
floorMicrosecond(float $precision = 1) : $this
Truncate the current instance microsecond with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorMicroseconds()
public
floorMicroseconds(float $precision = 1) : $this
Truncate the current instance microsecond with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorMillennia()
public
floorMillennia(float $precision = 1) : $this
Truncate the current instance millennium with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorMillennium()
public
floorMillennium(float $precision = 1) : $this
Truncate the current instance millennium with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorMillisecond()
public
floorMillisecond(float $precision = 1) : $this
Truncate the current instance millisecond with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorMilliseconds()
public
floorMilliseconds(float $precision = 1) : $this
Truncate the current instance millisecond with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorMinute()
public
floorMinute(float $precision = 1) : $this
Truncate the current instance minute with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorMinutes()
public
floorMinutes(float $precision = 1) : $this
Truncate the current instance minute with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorMonth()
public
floorMonth(float $precision = 1) : $this
Truncate the current instance month with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorMonths()
public
floorMonths(float $precision = 1) : $this
Truncate the current instance month with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorQuarter()
public
floorQuarter(float $precision = 1) : $this
Truncate the current instance quarter with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorQuarters()
public
floorQuarters(float $precision = 1) : $this
Truncate the current instance quarter with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorSecond()
public
floorSecond(float $precision = 1) : $this
Truncate the current instance second with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorSeconds()
public
floorSeconds(float $precision = 1) : $this
Truncate the current instance second with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorUnit()
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
staticfloorWeek()
public
floorWeek(float $precision = 1) : $this
Truncate the current instance day with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorWeeks()
public
floorWeeks(float $precision = 1) : $this
Truncate the current instance day with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorYear()
public
floorYear(float $precision = 1) : $this
Truncate the current instance year with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfloorYears()
public
floorYears(float $precision = 1) : $this
Truncate the current instance year with given precision.
Parameters
- $precision = 1 : float
Return values
$thisfollows()
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
boolforEach()
Execute a given function on each date of the period.
public
forEach(callable $callback) : void
Parameters
- $callback : callable
Tags
get()
Get a property allowing both `DatePeriod` snakeCase and camelCase names.
public
get(string $name) : bool|CarbonInterface|CarbonInterval|int|null
Parameters
- $name : string
Return values
bool|CarbonInterface|CarbonInterval|int|nullgetClock()
public
getClock() : WrapperClock|null
Return values
WrapperClock|nullgetDateClass()
Returns iteration item date class.
public
getDateClass() : string
Return values
stringgetDateInterval()
Get the underlying date interval.
public
getDateInterval() : CarbonInterval
Return values
CarbonIntervalgetEndDate()
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|nullgetFilters()
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
CarbonInterfacegetIncludedStartDate()
Return the start if it's included by option, else return the start + 1 period interval.
public
getIncludedStartDate() : CarbonInterface
Return values
CarbonInterfacegetIterator()
public
getIterator() : Generator
Return values
GeneratorgetOptions()
Get the period options.
public
getOptions() : int
Return values
intgetRecurrences()
Get number of recurrences.
public
getRecurrences() : int|float|null
Return values
int|float|nullgetSettings()
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
CarbonInterfacehasFilter()
Return whether given instance or name is in the filter stack.
public
hasFilter(callable|string $filter) : bool
Parameters
- $filter : callable|string
Return values
boolhasMacro()
Check if macro is registered.
public
static hasMacro(string $name) : bool
Parameters
- $name : string
Return values
boolhour()
public
static hour(mixed $hours) : static
Alias for hours().
Parameters
- $hours : mixed
Return values
statichours()
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
staticinstance()
Create a new instance from a DatePeriod or CarbonPeriod object.
public
static instance(mixed $period) : static
Parameters
- $period : mixed
Return values
staticinterval()
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|CarbonIntervalinvert()
public
static invert() : static
Create instance with inverted date interval or invert the interval if called on an instance.
Return values
staticinvertDateInterval()
Invert the period date interval.
public
invertDateInterval() : static
Return values
staticisConsecutiveWith()
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
Return values
boolisEnded()
Return true if end date is now or later.
public
isEnded() : bool
(Rather start/end are included by options is ignored.)
Return values
boolisEndExcluded()
Returns true if the end date should be excluded.
public
isEndExcluded() : bool
Return values
boolisEndIncluded()
Returns true if the end date should be included.
public
isEndIncluded() : bool
Return values
boolisFollowedBy()
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
boolisInProgress()
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
boolisStarted()
Return true if start date is now or later.
public
isStarted() : bool
(Rather start/end are included by options is ignored.)
Return values
boolisStartExcluded()
Returns true if the start date should be excluded.
public
isStartExcluded() : bool
Return values
boolisStartIncluded()
Returns true if the start date should be included.
public
isStartIncluded() : bool
Return values
boolisUnfilteredAndEndLess()
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
booljsonSerialize()
Specify data which should be serialized to JSON.
public
jsonSerialize() : array<string|int, CarbonInterface>
Tags
Return values
array<string|int, CarbonInterface>key()
Return the current key.
public
key() : int|null
Return values
int|nulllast()
Return the last date in the date period.
public
last() : CarbonInterface|null
Return values
CarbonInterface|nullmacro()
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
make()
Make a CarbonPeriod instance from given variable if possible.
public
static make(mixed $var) : static|null
Parameters
- $var : mixed
Return values
static|nullmap()
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
Return values
Generatormicrosecond()
public
static microsecond(mixed $microseconds) : static
Alias for microseconds().
Parameters
- $microseconds : mixed
Return values
staticmicroseconds()
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
staticmillisecond()
public
static millisecond(mixed $milliseconds) : static
Alias for milliseconds().
Parameters
- $milliseconds : mixed
Return values
staticmilliseconds()
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
staticminute()
public
static minute(mixed $minutes) : static
Alias for minutes().
Parameters
- $minutes : mixed
Return values
staticminutes()
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
staticmixin()
Register macros from a mixin object.
public
static mixin(object|string $mixin) : void
Parameters
- $mixin : object|string
Tags
month()
public
static month(mixed $months) : static
Alias for months().
Parameters
- $months : mixed
Return values
staticmonths()
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
staticne()
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
Return values
boolnext()
Move forward to the next date.
public
next() : void
Tags
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
booloptions()
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|nulloverlaps()
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
boolprepend()
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
staticprependFilter()
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
Return values
staticpush()
public
static push(mixed $callback, mixed $name) : static
Alias for filter().
Parameters
- $callback : mixed
- $name : mixed
Return values
staticrecurrences()
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
staticremoveFilter()
Remove a filter by instance or name.
public
removeFilter(callable|string $filter) : static
Parameters
- $filter : callable|string
Return values
staticresetDateInterval()
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
staticresetFilters()
Reset filters stack.
public
resetFilters() : static
Return values
staticresetToStringFormat()
Reset the format used to the default when type juggling a Carbon instance to a string
public
static resetToStringFormat() : void
rewind()
Rewind to the start date.
public
rewind() : void
Iterating over a date in the UTC timezone avoids bug during backward DST change.
Tags
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
staticroundCenturies()
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
$thisroundCentury()
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
$thisroundDay()
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
$thisroundDays()
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
$thisroundDecade()
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
$thisroundDecades()
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
$thisroundHour()
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
$thisroundHours()
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
$thisroundMicrosecond()
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
$thisroundMicroseconds()
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
$thisroundMillennia()
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
$thisroundMillennium()
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
$thisroundMillisecond()
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
$thisroundMilliseconds()
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
$thisroundMinute()
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
$thisroundMinutes()
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
$thisroundMonth()
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
$thisroundMonths()
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
$thisroundQuarter()
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
$thisroundQuarters()
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
$thisroundSecond()
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
$thisroundSeconds()
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
$thisroundUnit()
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
staticroundWeek()
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
$thisroundWeeks()
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
$thisroundYear()
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
$thisroundYears()
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
$thissecond()
public
static second(mixed $seconds) : static
Alias for seconds().
Parameters
- $seconds : mixed
Return values
staticseconds()
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
staticsetDateClass()
Set the iteration item class.
public
setDateClass(string $dateClass) : static
Parameters
- $dateClass : string
Return values
staticsetDateInterval()
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
Return values
staticsetDates()
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
staticsetEndDate()
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
Return values
staticsetFilters()
Set filters stack.
public
setFilters(array<string|int, mixed> $filters) : static
Parameters
- $filters : array<string|int, mixed>
Return values
staticsetOptions()
Change the period options.
public
setOptions(int|null $options) : static
Parameters
- $options : int|null
Return values
staticsetRecurrences()
Add a recurrences filter (set maximum number of recurrences).
public
setRecurrences(int|float|null $recurrences) : static
Parameters
- $recurrences : int|float|null
Tags
Return values
staticsetStartDate()
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
Return values
staticsetTimezone()
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
staticsettings()
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|staticsetToStringFormat()
public
static setToStringFormat(string|Closure|null $format) : void
Parameters
- $format : string|Closure|null
Tags
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
staticsince()
public
static since(mixed $date, mixed $inclusive) : static
Alias for start().
Parameters
- $date : mixed
- $inclusive : mixed
Return values
staticsinceNow()
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
staticskip()
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
boolspec()
Format the date period as ISO 8601.
public
spec() : string
Return values
stringstart()
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|CarbonInterfacestartsAfter()
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
boolstartsAfterOrAt()
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
boolstartsAt()
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
boolstartsBefore()
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
boolstartsBeforeOrAt()
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
boolstep()
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
staticstepBy()
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
statictimes()
public
static times(mixed $recurrences) : static
Alias for recurrences().
Parameters
- $recurrences : mixed
Return values
statictoArray()
Convert the date period into an array without changing current iteration state.
public
toArray() : array<string|int, CarbonInterface>
Return values
array<string|int, CarbonInterface>toDatePeriod()
Return native DatePeriod PHP object matching the current instance.
public
toDatePeriod() : DatePeriod
Tags
Return values
DatePeriodtoggle()
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
statictoggleOptions()
Toggle given options on or off.
public
toggleOptions(int $options[, bool|null $state = null ]) : static
Parameters
- $options : int
- $state : bool|null = null
Tags
Return values
statictoIso8601String()
Format the date period as ISO 8601.
public
toIso8601String() : string
Return values
stringtoString()
Convert the date period into a string.
public
toString() : string
Return values
stringuntil()
public
static until(mixed $date, mixed $inclusive) : static
Alias for end().
Parameters
- $date : mixed
- $inclusive : mixed
Return values
staticuntilNow()
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
staticvalid()
Check if the current position is valid.
public
valid() : bool
Return values
boolweek()
public
static week(mixed $weeks) : static
Alias for weeks().
Parameters
- $weeks : mixed
Return values
staticweeks()
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
staticyear()
public
static year(mixed $years) : static
Alias for years().
Parameters
- $years : mixed
Return values
staticyears()
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
staticaddExtraDebugInfos()
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
stringbindMacroContext()
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|nullcheckFilters()
Check whether current value and key pass all the filters.
protected
checkFilters() : bool|static::END_ITERATION
Return values
bool|static::END_ITERATIONcontext()
Return the current context from inside a macro callee or a null if static.
protected
static context() : static|null
Return values
static|nullcopyIfImmutable()
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
staticcreateFilterTuple()
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_ITERATIONfilterEndDate()
End date filter callback.
protected
filterEndDate(CarbonInterface $current) : bool|static::END_ITERATION
Parameters
- $current : CarbonInterface
Return values
bool|static::END_ITERATIONfilterRecurrences()
Recurrences filter callback (limits number of recurrences).
protected
filterRecurrences(CarbonInterface $current, int $key) : bool|callable
Parameters
- $current : CarbonInterface
- $key : int
Tags
Return values
bool|callablegetGetter()
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|nullhandleChangedParameters()
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
intervalHasTime()
Return whether given interval contains non zero value of any time unit.
protected
static intervalHasTime(DateInterval $interval) : bool
Parameters
- $interval : DateInterval
Return values
boolisCarbonPredicateMethod()
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
boolisIso8601()
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
boolisLocalStrictModeEnabled()
protected
isLocalStrictModeEnabled() : bool
Return values
boolparseIso8601()
Parse given ISO 8601 string into an array of arguments.
protected
static parseIso8601(string $iso) : array<string|int, mixed>
Parameters
- $iso : string
Tags
Return values
array<string|int, mixed>prepareForReturn()
Prepare given date to be returned to the external logic.
protected
prepareForReturn(CarbonInterface $date) : CarbonInterface
Parameters
- $date : CarbonInterface
Return values
CarbonInterfaceresolveCarbon()
Return the Carbon instance passed through, a now instance in the same timezone if null given or parse the input if string given.
protected
resolveCarbon([Carbon|CarbonPeriod|CarbonInterval|DateInterval|DatePeriod|DateTimeInterface|string|null $date = null ]) : CarbonInterface
Parameters
- $date : Carbon|CarbonPeriod|CarbonInterval|DateInterval|DatePeriod|DateTimeInterface|string|null = null
Return values
CarbonInterfaceresolveCarbonPeriod()
Resolve passed arguments or DatePeriod to a CarbonPeriod object.
protected
resolveCarbonPeriod(mixed $period, mixed ...$arguments) : self
Parameters
- $period : mixed
- $arguments : mixed
Return values
selfroundWith()
protected
roundWith(DateInterval|string|float|int $precision, callable|string $function) : static|null
Parameters
- $precision : DateInterval|string|float|int
- $function : callable|string
Return values
static|nullthis()
Return the current context from inside a macro callee or a new one if static.
protected
static this() : static
Return values
staticupdateInternalState()
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_ITERATIONconfigureTimezone()
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
stringgetEndFromRecurrences()
private
getEndFromRecurrences() : CarbonInterface|null
Return values
CarbonInterface|nullgetFactory()
private
getFactory() : Factory
Return values
FactorygetMixableMethods()
private
static getMixableMethods(self $context) : Generator
Parameters
- $context : self
Return values
GeneratorinitLocalFactory()
private
initLocalFactory() : void
isInfiniteDate()
private
isInfiniteDate(mixed $date) : bool
Parameters
- $date : mixed
Return values
booliterateUntilEnd()
private
iterateUntilEnd() : CarbonInterface|null
Return values
CarbonInterface|nullloadMixinClass()
private
static loadMixinClass(object|string $mixin) : void
Parameters
- $mixin : object|string
Tags
loadMixinTrait()
private
static loadMixinTrait(string $trait) : void
Parameters
- $trait : string
makeDateTime()
private
makeDateTime(mixed $value) : DateTimeInterface|null
Parameters
- $value : mixed
Return values
DateTimeInterface|nullmakeInterval()
private
static makeInterval(mixed $input) : CarbonInterval|null
Parameters
- $input : mixed
Return values
CarbonInterval|nullmakeTimezone()
private
static makeTimezone(mixed $input) : CarbonTimeZone|null
Parameters
- $input : mixed
Return values
CarbonTimeZone|nullorderCouple()
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|nullsetDefaultParameters()
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