Skip to content

API reference / Quittio \ Core \ Support

Date

final readonly class in quittio/core · implements JsonSerializable, Stringable

Quittio\Core\Support\Date · Source

Calendar date without time of day.

Invoice dates are legal dates in the issuer's time zone. Storing them as year/month/day makes it impossible for a UTC conversion to shift them to the previous or next day.

Methods#

MethodDescription
->__toString()
->addDays()A new date $days later, or earlier for a negative number.
->compareTo()Negative, zero or positive when this date is before, the same as or after $other, e.g. for usort().
->diffInDays()Days from this date to $other: positive when $other is later, negative when it is earlier.
->equals()Whether both are the same calendar date.
->format()The date formatted with a format of date(), e.g. "d.m.Y"; time parts are midnight.
::fromFormat102()Strict CII date in format 102 (YYYYMMDD), as used for incoming documents.
::fromIsoDate()Strict ISO 8601 calendar date (YYYY-MM-DD) with an optional time zone (Z, +01:00), as used by UBL (xs:date). The time zone does not shift the calendar date.
->isAfter()Whether this date is later than $other.
->isBefore()Whether this date is earlier than $other.
->jsonSerialize()The ISO date (YYYY-MM-DD) for json_encode().
::of()The date of $year, $month and $day. Throws an InvalidArgumentException for a date that does not exist, e.g. February 30.
::parse()Accepts ISO dates (2026-10-03), the CII format 102 (20261003), date-time strings and DateTimeInterface instances.
->toCarbon()Midnight of this date in $timezone, by default the default time zone of PHP.
::today()Today's date in $timezone, by default the default time zone of PHP.
->toFormat102()Date in UN/CEFACT format 102 (CCYYMMDD).
->toIsoString()ISO 8601 date (YYYY-MM-DD), as used for JSON and storage.

__toString()#

public function __toString(): string
Returns
string

addDays()#

public function addDays(int $days): self

A new date $days later, or earlier for a negative number.

ParameterTypeDescription
$daysint
Returns
self

compareTo()#

public function compareTo(self $other): int

Negative, zero or positive when this date is before, the same as or after $other, e.g. for usort().

ParameterTypeDescription
$otherself
Returns
int

diffInDays()#

public function diffInDays(self $other): int

Days from this date to $other: positive when $other is later, negative when it is earlier.

ParameterTypeDescription
$otherself
Returns
int

equals()#

public function equals(self $other): bool

Whether both are the same calendar date.

ParameterTypeDescription
$otherself
Returns
bool

format()#

public function format(string $format): string

The date formatted with a format of date(), e.g. "d.m.Y"; time parts are midnight.

ParameterTypeDescription
$formatstring
Returns
string

fromFormat102()#

public static function fromFormat102(string $value): self

static

Strict CII date in format 102 (YYYYMMDD), as used for incoming documents.

ParameterTypeDescription
$valuestring
Returns
self
Throws
InvalidArgumentException

fromIsoDate()#

public static function fromIsoDate(string $value): self

static

Strict ISO 8601 calendar date (YYYY-MM-DD) with an optional time zone (Z, +01:00), as used by UBL (xs:date). The time zone does not shift the calendar date.

ParameterTypeDescription
$valuestring
Returns
self
Throws
InvalidArgumentException

isAfter()#

public function isAfter(self $other): bool

Whether this date is later than $other.

ParameterTypeDescription
$otherself
Returns
bool

isBefore()#

public function isBefore(self $other): bool

Whether this date is earlier than $other.

ParameterTypeDescription
$otherself
Returns
bool

jsonSerialize()#

public function jsonSerialize(): string

The ISO date (YYYY-MM-DD) for json_encode().

Returns
string

of()#

public static function of(int $year, int $month, int $day): self

static

The date of $year, $month and $day. Throws an InvalidArgumentException for a date that does not exist, e.g. February 30.

ParameterTypeDescription
$yearint
$monthint
$dayint
Returns
self

parse()#

public static function parse(
    self|DateTimeInterface|string $value,
    DateTimeZone|string|null $timezone = null,
): self

static

Accepts ISO dates (2026-10-03), the CII format 102 (20261003), date-time strings and DateTimeInterface instances.

A DateTimeInterface is first converted into $timezone (if given), so that the calendar date matches the issuer's local date.

ParameterTypeDescription
$valueself|DateTimeInterface|string
$timezoneDateTimeZone|string|null = null
Returns
self

toCarbon()#

public function toCarbon(DateTimeZone|string|null $timezone = null): CarbonImmutable

Midnight of this date in $timezone, by default the default time zone of PHP.

ParameterTypeDescription
$timezoneDateTimeZone|string|null = null
Returns
Carbon\CarbonImmutable

today()#

public static function today(DateTimeZone|string|null $timezone = null): self

static

Today's date in $timezone, by default the default time zone of PHP.

ParameterTypeDescription
$timezoneDateTimeZone|string|null = null
Returns
self

toFormat102()#

public function toFormat102(): string

Date in UN/CEFACT format 102 (CCYYMMDD).

Returns
string

toIsoString()#

public function toIsoString(): string

ISO 8601 date (YYYY-MM-DD), as used for JSON and storage.

Returns
string

The open core packages are MIT licensed. The legal wording of the country packs must be confirmed by a tax adviser.