API reference / Quittio \ Core \ Support
DatedValues
final readonly class in quittio/core
Quittio\Core\Support\DatedValues · Source
Values that change on dates, e.g. tax rates or reference interest rates: every value holds from its date until the next change.
Methods#
| Method | Description |
|---|---|
->__construct() | |
->changes() | Every change: ISO date => value, sorted by date. |
->lastChange() | Date of the last change; null without values. |
->on() | The value that holds on the date; null before the first change. |
->periods() | The periods of constant value between two dates (both included), in order; days before the first change are left out. |
->withValue() | A copy with a value that holds from $from on; an existing value of that date is replaced. |
__construct()#
public function __construct(array<string, string> $values)| Parameter | Type | Description |
|---|---|---|
$values | array<string, string> | ISO date (YYYY-MM-DD) => value from that date on |
- Throws
InvalidArgumentException– for a key that is no ISO date
changes()#
public function changes(): array<string, string>Every change: ISO date => value, sorted by date.
- Returns
array<string, string>
lastChange()#
public function lastChange(): ?DateDate of the last change; null without values.
- Returns
?Date
on()#
public function on(Date $date): ?stringThe value that holds on the date; null before the first change.
| Parameter | Type | Description |
|---|---|---|
$date | Date |
- Returns
?string
periods()#
public function periods(
Date $from,
Date $until,
): list<array{from: Date, until: Date, value: string}>The periods of constant value between two dates (both included), in order; days before the first change are left out.
| Parameter | Type | Description |
|---|---|---|
$from | Date | |
$until | Date |
withValue()#
public function withValue(Date|string $from, string $value): selfA copy with a value that holds from $from on; an existing value of that date is replaced.
| Parameter | Type | Description |
|---|---|---|
$from | Date|string | |
$value | string |
- Returns
self