Modifiers
Trait Modifiers.
Returns dates relative to current date using modifier short-hand.
Table of Contents
Properties
- $midDayAt : int
- Midday/noon hour.
Methods
- average() : static
- Modify the current instance to the average of a given instance (default now) and the current instance (second-precision).
- change() : static
- Similar to native modify() method of DateTime but can handle more grammars.
- closest() : static
- Get the closest date from the instance (second-precision).
- farthest() : static
- Get the farthest date from the instance (second-precision).
- firstOfMonth() : static
- Modify to the first occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the first day of the current month. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
- firstOfQuarter() : static
- Modify to the first occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the first day of the current quarter. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
- firstOfYear() : static
- Modify to the first occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the first day of the current year. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
- getMidDayAt() : int
- get midday/noon hour
- lastOfMonth() : static
- Modify to the last occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the last day of the current month. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
- lastOfQuarter() : static
- Modify to the last occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the last day of the current quarter. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
- lastOfYear() : static
- Modify to the last occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the last day of the current year. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
- max() : static
- Get the maximum instance between a given instance (default now) and the current instance.
- maximum() : static
- Get the maximum instance between a given instance (default now) and the current instance.
- midDay() : static
- Modify to midday, default to self::$midDayAt
- min() : static
- Get the minimum instance between a given instance (default now) and the current instance.
- minimum() : static
- Get the minimum instance between a given instance (default now) and the current instance.
- modify() : static
- Calls \DateTime::modify if mutable or \DateTimeImmutable::modify else.
- next() : static
- Modify to the next occurrence of a given modifier such as a day of the week. If no modifier is provided, modify to the next occurrence of the current day of the week. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
- nextWeekday() : static
- Go forward to the next weekday.
- nextWeekendDay() : static
- Go forward to the next weekend day.
- nthOfMonth() : mixed
- Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside the scope of the current month, then return false and no modifications are made.
- nthOfQuarter() : mixed
- Modify to the given occurrence of a given day of the week in the current quarter. If the calculated occurrence is outside the scope of the current quarter, then return false and no modifications are made.
- nthOfYear() : mixed
- Modify to the given occurrence of a given day of the week in the current year. If the calculated occurrence is outside the scope of the current year, then return false and no modifications are made.
- previous() : static
- Modify to the previous occurrence of a given modifier such as a day of the week. If no dayOfWeek is provided, modify to the previous occurrence of the current day of the week. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
- previousWeekday() : static
- Go backward to the previous weekday.
- previousWeekendDay() : static
- Go backward to the previous weekend day.
- setMidDayAt() : void
- nextOrPreviousDay() : static
- Go forward or backward to the next week- or weekend-day.
Properties
$midDayAt
Midday/noon hour.
protected
static int
$midDayAt
= 12
Methods
average()
Modify the current instance to the average of a given instance (default now) and the current instance (second-precision).
public
average([Carbon|DateTimeInterface|null $date = null ]) : static
Parameters
- $date : Carbon|DateTimeInterface|null = null
Return values
staticchange()
Similar to native modify() method of DateTime but can handle more grammars.
public
change(string $modifier) : static
Parameters
- $modifier : string
Tags
Return values
staticclosest()
Get the closest date from the instance (second-precision).
public
closest(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2) : static
Parameters
Return values
staticfarthest()
Get the farthest date from the instance (second-precision).
public
farthest(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2) : static
Parameters
Return values
staticfirstOfMonth()
Modify to the first occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the first day of the current month. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
public
firstOfMonth([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
Return values
staticfirstOfQuarter()
Modify to the first occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the first day of the current quarter. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
public
firstOfQuarter([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
-
day of the week default null
Return values
staticfirstOfYear()
Modify to the first occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the first day of the current year. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
public
firstOfYear([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
-
day of the week default null
Return values
staticgetMidDayAt()
get midday/noon hour
public
static getMidDayAt() : int
Return values
intlastOfMonth()
Modify to the last occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the last day of the current month. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
public
lastOfMonth([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
Return values
staticlastOfQuarter()
Modify to the last occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the last day of the current quarter. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
public
lastOfQuarter([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
-
day of the week default null
Return values
staticlastOfYear()
Modify to the last occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the last day of the current year. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
public
lastOfYear([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
-
day of the week default null
Return values
staticmax()
Get the maximum instance between a given instance (default now) and the current instance.
public
max([Carbon|DateTimeInterface|mixed $date = null ]) : static
Parameters
- $date : Carbon|DateTimeInterface|mixed = null
Return values
staticmaximum()
Get the maximum instance between a given instance (default now) and the current instance.
public
maximum([Carbon|DateTimeInterface|mixed $date = null ]) : static
Parameters
- $date : Carbon|DateTimeInterface|mixed = null
Tags
Return values
staticmidDay()
Modify to midday, default to self::$midDayAt
public
midDay() : static
Return values
staticmin()
Get the minimum instance between a given instance (default now) and the current instance.
public
min([Carbon|DateTimeInterface|mixed $date = null ]) : static
Parameters
- $date : Carbon|DateTimeInterface|mixed = null
Return values
staticminimum()
Get the minimum instance between a given instance (default now) and the current instance.
public
minimum([Carbon|DateTimeInterface|mixed $date = null ]) : static
Parameters
- $date : Carbon|DateTimeInterface|mixed = null
Tags
Return values
staticmodify()
Calls \DateTime::modify if mutable or \DateTimeImmutable::modify else.
public
modify(mixed $modify) : static
Parameters
- $modify : mixed
Tags
Return values
staticnext()
Modify to the next occurrence of a given modifier such as a day of the week. If no modifier is provided, modify to the next occurrence of the current day of the week. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
public
next([string|int|null $modifier = null ]) : static
Parameters
- $modifier : string|int|null = null
Return values
staticnextWeekday()
Go forward to the next weekday.
public
nextWeekday() : static
Return values
staticnextWeekendDay()
Go forward to the next weekend day.
public
nextWeekendDay() : static
Return values
staticnthOfMonth()
Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside the scope of the current month, then return false and no modifications are made.
public
nthOfMonth(int $nth, int $dayOfWeek) : mixed
Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
- $nth : int
- $dayOfWeek : int
nthOfQuarter()
Modify to the given occurrence of a given day of the week in the current quarter. If the calculated occurrence is outside the scope of the current quarter, then return false and no modifications are made.
public
nthOfQuarter(int $nth, int $dayOfWeek) : mixed
Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
- $nth : int
- $dayOfWeek : int
nthOfYear()
Modify to the given occurrence of a given day of the week in the current year. If the calculated occurrence is outside the scope of the current year, then return false and no modifications are made.
public
nthOfYear(int $nth, int $dayOfWeek) : mixed
Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
- $nth : int
- $dayOfWeek : int
previous()
Modify to the previous occurrence of a given modifier such as a day of the week. If no dayOfWeek is provided, modify to the previous occurrence of the current day of the week. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
public
previous([string|int|null $modifier = null ]) : static
Parameters
- $modifier : string|int|null = null
Return values
staticpreviousWeekday()
Go backward to the previous weekday.
public
previousWeekday() : static
Return values
staticpreviousWeekendDay()
Go backward to the previous weekend day.
public
previousWeekendDay() : static
Return values
staticsetMidDayAt()
public
static setMidDayAt(int $hour) : void
Parameters
- $hour : int
-
midday hour
Tags
nextOrPreviousDay()
Go forward or backward to the next week- or weekend-day.
private
nextOrPreviousDay([bool $weekday = true ][, bool $forward = true ]) : static
Parameters
- $weekday : bool = true
- $forward : bool = true