class Date implements Stringable (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected $constraints

The constraints for the date rule.

Methods

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

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

$this|TUnlessReturnType
unless($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, object|callable $macro)

Register a custom macro.

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

Mix another object into the class.

static bool
hasMacro(string $name)

Checks 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.

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.

Details

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

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

Parameters

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

Return Value

$this|TWhenReturnType

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

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

Parameters

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

Return Value

$this|TUnlessReturnType

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

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

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

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

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

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

Date format(string $format)

Ensure the date has the given format.

Parameters

string $format

Return Value

Date

Date beforeToday()

Ensure the date is before today.

Return Value

Date

Date afterToday()

Ensure the date is after today.

Return Value

Date

Date todayOrBefore()

Ensure the date is before or equal to today.

Return Value

Date

Date todayOrAfter()

Ensure the date is after or equal to today.

Return Value

Date

Date before(DateTimeInterface|string $date)

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

Parameters

DateTimeInterface|string $date

Return Value

Date

Date after(DateTimeInterface|string $date)

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

Parameters

DateTimeInterface|string $date

Return Value

Date

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

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

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

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

protected Date addRule(array|string $rules)

Add custom rules to the validation rules array.

Parameters

array|string $rules

Return Value

Date

protected string formatDate(DateTimeInterface|string $date)

Format the date for the validation rule.

Parameters

DateTimeInterface|string $date

Return Value

string

string __toString()

Convert the rule to a validation string.

Return Value

string