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#
| Method | Description |
|---|---|
->__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): selfA new date $days later, or earlier for a negative number.
| Parameter | Type | Description |
|---|---|---|
$days | int |
- Returns
self
compareTo()#
public function compareTo(self $other): intNegative, zero or positive when this date is before, the same as or after $other, e.g. for usort().
| Parameter | Type | Description |
|---|---|---|
$other | self |
- Returns
int
diffInDays()#
public function diffInDays(self $other): intDays from this date to $other: positive when $other is later, negative when it is earlier.
| Parameter | Type | Description |
|---|---|---|
$other | self |
- Returns
int
equals()#
public function equals(self $other): boolWhether both are the same calendar date.
| Parameter | Type | Description |
|---|---|---|
$other | self |
- Returns
bool
format()#
public function format(string $format): stringThe date formatted with a format of date(), e.g. "d.m.Y"; time parts are midnight.
| Parameter | Type | Description |
|---|---|---|
$format | string |
- Returns
string
fromFormat102()#
public static function fromFormat102(string $value): selfStrict CII date in format 102 (YYYYMMDD), as used for incoming documents.
| Parameter | Type | Description |
|---|---|---|
$value | string |
- Returns
self- Throws
InvalidArgumentException
fromIsoDate()#
public static function fromIsoDate(string $value): selfStrict 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.
| Parameter | Type | Description |
|---|---|---|
$value | string |
- Returns
self- Throws
InvalidArgumentException
isAfter()#
public function isAfter(self $other): boolWhether this date is later than $other.
| Parameter | Type | Description |
|---|---|---|
$other | self |
- Returns
bool
isBefore()#
public function isBefore(self $other): boolWhether this date is earlier than $other.
| Parameter | Type | Description |
|---|---|---|
$other | self |
- Returns
bool
jsonSerialize()#
public function jsonSerialize(): stringThe ISO date (YYYY-MM-DD) for json_encode().
- Returns
string
of()#
public static function of(int $year, int $month, int $day): selfThe date of $year, $month and $day. Throws an InvalidArgumentException for a date that does not exist, e.g. February 30.
| Parameter | Type | Description |
|---|---|---|
$year | int | |
$month | int | |
$day | int |
- Returns
self
parse()#
public static function parse(
self|DateTimeInterface|string $value,
DateTimeZone|string|null $timezone = null,
): selfAccepts 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.
| Parameter | Type | Description |
|---|---|---|
$value | self|DateTimeInterface|string | |
$timezone | DateTimeZone|string|null = null |
- Returns
self
toCarbon()#
public function toCarbon(DateTimeZone|string|null $timezone = null): CarbonImmutableMidnight of this date in $timezone, by default the default time zone of PHP.
| Parameter | Type | Description |
|---|---|---|
$timezone | DateTimeZone|string|null = null |
- Returns
Carbon\CarbonImmutable
today()#
public static function today(DateTimeZone|string|null $timezone = null): selfToday's date in $timezone, by default the default time zone of PHP.
| Parameter | Type | Description |
|---|---|---|
$timezone | DateTimeZone|string|null = null |
- Returns
self
toFormat102()#
public function toFormat102(): stringDate in UN/CEFACT format 102 (CCYYMMDD).
- Returns
string
toIsoString()#
public function toIsoString(): stringISO 8601 date (YYYY-MM-DD), as used for JSON and storage.
- Returns
string