trait Modifiers

Trait Modifiers.

Returns dates relative to current date using modifier short-hand.

Properties

staticprotectedint $midDayAt Midday/noon hour.

Methods

static int
getMidDayAt()

get midday/noon hour

static void
setMidDayAt(int$hour)deprecated

No description

midDay()

Modify to midday, default to self::$midDayAt

next(string|int|null$modifier =null)

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()

Go forward to the next weekday.

previousWeekday()

Go backward to the previous weekday.

nextWeekendDay()

Go forward to the next weekend day.

previousWeekendDay()

Go backward to the previous weekend day.

previous(string|int|null$modifier =null)

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.

firstOfMonth(int|null$dayOfWeek =null)

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.

lastOfMonth(int|null$dayOfWeek =null)

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.

mixed
nthOfMonth(int$nth,int$dayOfWeek)

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.

firstOfQuarter(int|null$dayOfWeek =null)

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.

lastOfQuarter(int|null$dayOfWeek =null)

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.

mixed
nthOfQuarter(int$nth,int$dayOfWeek)

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.

firstOfYear(int|null$dayOfWeek =null)

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.

lastOfYear(int|null$dayOfWeek =null)

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.

mixed
nthOfYear(int$nth,int$dayOfWeek)

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.

average(Carbon|DateTimeInterface|null$date =null)

Modify the current instance to the average of a given instance (default now) and the current instance (second-precision).

closest(Carbon|DateTimeInterface|mixed$date1,Carbon|DateTimeInterface|mixed$date2)

Get the closest date from the instance (second-precision).

farthest(Carbon|DateTimeInterface|mixed$date1,Carbon|DateTimeInterface|mixed$date2)

Get the farthest date from the instance (second-precision).

min(Carbon|DateTimeInterface|mixed$date =null)

Get the minimum instance between a given instance (default now) and the current instance.

minimum(Carbon|DateTimeInterface|mixed$date =null)

Get the minimum instance between a given instance (default now) and the current instance.

max(Carbon|DateTimeInterface|mixed$date =null)

Get the maximum instance between a given instance (default now) and the current instance.

maximum(Carbon|DateTimeInterface|mixed$date =null)

Get the maximum instance between a given instance (default now) and the current instance.

modify($modify)

No description

change(string$modifier)

Similar to native modify() method of DateTime but can handle more grammars.

Details

at line36
staticint getMidDayAt()

get midday/noon hour

Return Value

int

at line55
staticvoid setMidDayAt(int$hour)deprecated

deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather consider mid-day is always 12pm, then if you need to test if it's an other hour, test it explicitly: $date->format('G') == 13 or to set explicitly to a given hour: $date->setTime(13, 0, 0, 0) Set midday/noon hour

Parameters

int $hour midday hour

Return Value

void

at line65
Modifiers midDay()

Modify to midday, default to self::$midDayAt

Return Value

Modifiers

at line80
Modifiers next(string|int|null$modifier =null)

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.

Parameters

string|int|null $modifier

Return Value

Modifiers

at line117
Modifiers nextWeekday()

Go forward to the next weekday.

Return Value

Modifiers

at line127
Modifiers previousWeekday()

Go backward to the previous weekday.

Return Value

Modifiers

at line137
Modifiers nextWeekendDay()

Go forward to the next weekend day.

Return Value

Modifiers

at line147
Modifiers previousWeekendDay()

Go backward to the previous weekend day.

Return Value

Modifiers

at line162
Modifiers previous(string|int|null$modifier =null)

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.

Parameters

string|int|null $modifier

Return Value

Modifiers

at line183
Modifiers firstOfMonth(int|null$dayOfWeek =null)

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.

Parameters

int|null $dayOfWeek

Return Value

Modifiers

at line204
Modifiers lastOfMonth(int|null$dayOfWeek =null)

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.

Parameters

int|null $dayOfWeek

Return Value

Modifiers

at line226
mixed nthOfMonth(int$nth,int$dayOfWeek)

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.

Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.

Parameters

int $nth
int $dayOfWeek

Return Value

mixed

at line245
Modifiers firstOfQuarter(int|null$dayOfWeek =null)

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.

Parameters

int|null $dayOfWeek day of the week default null

Return Value

Modifiers

at line260
Modifiers lastOfQuarter(int|null$dayOfWeek =null)

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.

Parameters

int|null $dayOfWeek day of the week default null

Return Value

Modifiers

at line276
mixed nthOfQuarter(int$nth,int$dayOfWeek)

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.

Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.

Parameters

int $nth
int $dayOfWeek

Return Value

mixed

at line296
Modifiers firstOfYear(int|null$dayOfWeek =null)

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.

Parameters

int|null $dayOfWeek day of the week default null

Return Value

Modifiers

at line311
Modifiers lastOfYear(int|null$dayOfWeek =null)

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.

Parameters

int|null $dayOfWeek day of the week default null

Return Value

Modifiers

at line327
mixed nthOfYear(int$nth,int$dayOfWeek)

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.

Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.

Parameters

int $nth
int $dayOfWeek

Return Value

mixed

at line342
Modifiers average(Carbon|DateTimeInterface|null$date =null)

Modify the current instance to the average of a given instance (default now) and the current instance (second-precision).

Parameters

Carbon|DateTimeInterface|null $date

Return Value

Modifiers

at line355
Modifiers closest(Carbon|DateTimeInterface|mixed$date1,Carbon|DateTimeInterface|mixed$date2)

Get the closest date from the instance (second-precision).

Parameters

Carbon|DateTimeInterface|mixed $date1
Carbon|DateTimeInterface|mixed $date2

Return Value

Modifiers

at line368
Modifiers farthest(Carbon|DateTimeInterface|mixed$date1,Carbon|DateTimeInterface|mixed$date2)

Get the farthest date from the instance (second-precision).

Parameters

Carbon|DateTimeInterface|mixed $date1
Carbon|DateTimeInterface|mixed $date2

Return Value

Modifiers

at line380
Modifiers min(Carbon|DateTimeInterface|mixed$date =null)

Get the minimum instance between a given instance (default now) and the current instance.

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

Modifiers

at line396
Modifiers minimum(Carbon|DateTimeInterface|mixed$date =null)

Get the minimum instance between a given instance (default now) and the current instance.

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

Modifiers

See also

min()

at line408
Modifiers max(Carbon|DateTimeInterface|mixed$date =null)

Get the maximum instance between a given instance (default now) and the current instance.

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

Modifiers

at line424
Modifiers maximum(Carbon|DateTimeInterface|mixed$date =null)

Get the maximum instance between a given instance (default now) and the current instance.

Parameters

Carbon|DateTimeInterface|mixed $date

Return Value

Modifiers

See also

max()

at line437
modify($modify)

Parameters

$modify

at line456
Modifiers change(string$modifier)

Similar to native modify() method of DateTime but can handle more grammars.

Parameters

string $modifier

Return Value

Modifiers