php-cooper

CooperDate
in package
implements Stringable, JsonSerializable

FinalYes

A CASC local date (CASC.md ยง6.6) -- `1979-05-27` -- with no time or zone attached, matching Elixir's `Date`. PHP has no date-only type, and a `DateTimeImmutable` at midnight would invent a time and a zone the document never stated; `toDateTimeImmutable()` makes that choice explicit when it is wanted.

Table of Contents

Interfaces

Stringable
JsonSerializable

Properties

$day  : int
$month  : int
$year  : int

Methods

__construct()  : mixed
__toString()  : string
equals()  : bool
jsonSerialize()  : string
Encodes as the same text `__toString()` returns.
toDateTimeImmutable()  : DateTimeImmutable
Midnight on this date, in `$timezone` (default: PHP's default zone).

Properties

Methods

__construct()

public __construct(int $year, int $month, int $day) : mixed
Parameters
$year : int

the year

$month : int

the month, 1..12

$day : int

the day of the month

Tags
throws
InvalidArgumentException

when the date does not exist

__toString()

public __toString() : string
Return values
string —

the ISO 8601 form, YYYY-MM-DD

equals()

public equals(mixed $other) : bool
Parameters
$other : mixed

the value to compare against

Return values
bool —

true for the same calendar date

jsonSerialize()

Encodes as the same text `__toString()` returns.

public jsonSerialize() : string
Return values
string —

the string form

toDateTimeImmutable()

Midnight on this date, in `$timezone` (default: PHP's default zone).

public toDateTimeImmutable([DateTimeZone|null $timezone = null ]) : DateTimeImmutable
Parameters
$timezone : DateTimeZone|null = null

the zone to place the date in

Return values
DateTimeImmutable —

midnight at the start of this date

On this page

Search results