Iso8601Interval
Represents and manipulates ISO 8601 time intervals.
An interval is two ISO 8601 expressions joined by a / separator. Three
bounded forms are supported:
<start>/<end>— two strict date-times<start>/<duration>— a start date-time and a duration<duration>/<end>— a duration and an end date-time
The single-<duration> short form is intentionally rejected (use
Iso8601Duration for that). Open intervals (--/<end> and
<start>/--) are not supported in this release.
start and end are always available as Iso8601DateTime objects.
When the input form omits one of them, it is computed from the duration.
The duration property reflects the input: it is null when the input
form was <start>/<end>. The iso round-trip preserves the original form.
Example usage:
use org\iso\Iso8601Interval;
$i = new Iso8601Interval('2026-05-14T00:00:00Z/P1D');
echo $i->start->iso; // "2026-05-14T00:00:00Z"
echo $i->end->iso; // "2026-05-15T00:00:00Z" (computed)
echo $i->duration->iso; // "P1D"
echo $i->iso; // "2026-05-14T00:00:00Z/P1D" (form preserved)
$i->contains(new DateTimeImmutable('2026-05-14T12:00:00Z')); // true
$other = new Iso8601Interval('2026-05-14T18:00:00Z/2026-05-16T00:00:00Z');
$i->overlaps($other); // true
Tags
Table of Contents
Constants
- SEPARATOR : string = '/'
- Interval separator.
- ZERO : string = '1970-01-01T00:00:00Z/PT0S'
- Zero interval constant: a zero-duration interval anchored at the Unix epoch.
Properties
- $duration : Iso8601Duration|null
- Duration of the interval as written in the input.
- $end : Iso8601DateTime
- End of the interval (always available, computed if needed).
- $iso : string
- ISO string representation. Round-trip preserves the input form.
- $start : Iso8601DateTime
- Start of the interval (always available, computed if needed).
- $_duration : Iso8601Duration|null
- $_end : Iso8601DateTime
- $_iso : string
- $_start : Iso8601DateTime
Methods
- __construct() : mixed
- Creates a new Iso8601Interval instance.
- __toString() : string
- String cast returns the ISO representation.
- contains() : bool
- Tests whether the given instant lies within the interval.
- overlaps() : bool
- Tests whether this interval overlaps another.
Constants
SEPARATOR
Interval separator.
public
string
SEPARATOR
= '/'
ZERO
Zero interval constant: a zero-duration interval anchored at the Unix epoch.
public
string
ZERO
= '1970-01-01T00:00:00Z/PT0S'
Properties
$duration read-only virtual
Duration of the interval as written in the input.
public
Iso8601Duration|null
$duration
null when the input form was <start>/<end>.
Hooks
public
Iso8601Duration|null
get
$end read-only virtual
End of the interval (always available, computed if needed).
public
Iso8601DateTime
$end
Hooks
public
Iso8601DateTime
get
$iso virtual
ISO string representation. Round-trip preserves the input form.
public
string
$iso
Tags
Hooks
public
string
get
public
set
$start read-only virtual
Start of the interval (always available, computed if needed).
public
Iso8601DateTime
$start
Hooks
public
Iso8601DateTime
get
$_duration
private
Iso8601Duration|null
$_duration
= null
$_end
private
Iso8601DateTime
$_end
$_iso
private
string
$_iso
$_start
private
Iso8601DateTime
$_start
Methods
__construct()
Creates a new Iso8601Interval instance.
public
__construct([string|null $iso = null ]) : mixed
Parameters
- $iso : string|null = null
-
ISO 8601 interval string, or null for the zero interval (ZERO)
Tags
__toString()
String cast returns the ISO representation.
public
__toString() : string
Return values
stringcontains()
Tests whether the given instant lies within the interval.
public
contains(DateTimeInterface|Iso8601DateTime $instant) : bool
The interval is treated as half-open: [start, end). The start instant
is included, the end instant is excluded.
Parameters
- $instant : DateTimeInterface|Iso8601DateTime
Return values
booloverlaps()
Tests whether this interval overlaps another.
public
overlaps(self $other) : bool
Two half-open intervals [a1, a2) and [b1, b2) overlap iff
a1 < b2 && b1 < a2. Adjacent intervals (one ending where the other
begins) do not overlap.
Parameters
- $other : self