class Date implements Stringable

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected string|null $format

The format of the date.

protected array $constraints

The constraints for the date rule.

Methods

mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

format(string $format)

Ensure the date has the given format.

beforeToday()

Ensure the date is before today.

afterToday()

Ensure the date is after today.

todayOrBefore()

Ensure the date is before or equal to today.

todayOrAfter()

Ensure the date is after or equal to today.

past()

Ensure the date is in the past.

future()

Ensure the date is in the future.

nowOrPast()

Ensure the date is now or in the past.

nowOrFuture()

Ensure the date is now or in the future.

before(DateTimeInterface|string $date)

Ensure the date is before the given date or date field.

after(DateTimeInterface|string $date)

Ensure the date is after the given date or date field.

beforeOrEqual(DateTimeInterface|string $date)

Ensure the date is on or before the specified date or date field.

afterOrEqual(DateTimeInterface|string $date)

Ensure the date is on or after the given date or date field.

between(DateTimeInterface|string $from, DateTimeInterface|string $to)

Ensure the date is between two dates or date fields.

betweenOrEqual(DateTimeInterface|string $from, DateTimeInterface|string $to)

Ensure the date is between or equal to two dates or date fields.

addRule(array|string $rules)

Add custom rules to the validation rules array.

string
formatDate(DateTimeInterface|string $date)

Format the date for the validation rule.

string
__toString()

Convert the rule to a validation string.

static void
flushState()

Flush all static state.

Details

in Conditionable at line 23
mixed when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in Conditionable at line 56
mixed unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in Macroable at line 28
static void macro(string $name, callable|object $macro)

Register a custom macro.

Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 41
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 68
static void flushMacros()

Flush the existing macros.

Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 31
Date format(string $format)

Ensure the date has the given format.

Parameters

string $format

Return Value

Date

at line 41
Date beforeToday()

Ensure the date is before today.

Return Value

Date

at line 49
Date afterToday()

Ensure the date is after today.

Return Value

Date

at line 57
Date todayOrBefore()

Ensure the date is before or equal to today.

Return Value

Date

at line 65
Date todayOrAfter()

Ensure the date is after or equal to today.

Return Value

Date

at line 73
Date past()

Ensure the date is in the past.

Return Value

Date

at line 81
Date future()

Ensure the date is in the future.

Return Value

Date

at line 89
Date nowOrPast()

Ensure the date is now or in the past.

Return Value

Date

at line 97
Date nowOrFuture()

Ensure the date is now or in the future.

Return Value

Date

at line 105
Date before(DateTimeInterface|string $date)

Ensure the date is before the given date or date field.

Parameters

DateTimeInterface|string $date

Return Value

Date

at line 113
Date after(DateTimeInterface|string $date)

Ensure the date is after the given date or date field.

Parameters

DateTimeInterface|string $date

Return Value

Date

at line 121
Date beforeOrEqual(DateTimeInterface|string $date)

Ensure the date is on or before the specified date or date field.

Parameters

DateTimeInterface|string $date

Return Value

Date

at line 129
Date afterOrEqual(DateTimeInterface|string $date)

Ensure the date is on or after the given date or date field.

Parameters

DateTimeInterface|string $date

Return Value

Date

at line 137
Date between(DateTimeInterface|string $from, DateTimeInterface|string $to)

Ensure the date is between two dates or date fields.

Parameters

DateTimeInterface|string $from
DateTimeInterface|string $to

Return Value

Date

at line 145
Date betweenOrEqual(DateTimeInterface|string $from, DateTimeInterface|string $to)

Ensure the date is between or equal to two dates or date fields.

Parameters

DateTimeInterface|string $from
DateTimeInterface|string $to

Return Value

Date

at line 153
protected Date addRule(array|string $rules)

Add custom rules to the validation rules array.

Parameters

array|string $rules

Return Value

Date

at line 163
protected string formatDate(DateTimeInterface|string $date)

Format the date for the validation rule.

Parameters

DateTimeInterface|string $date

Return Value

string

at line 173
string __toString()

Convert the rule to a validation string.

Return Value

string

at line 184
static void flushState()

Flush all static state.

Return Value

void