Temporal
in package
FinalYes
ISO 8601 parsing/formatting shared by the `.dxn` text parser and printer for `date`/`time`/`timestamp`/`datetime`/`duration` -- one implementation so encode/decode never drift apart. Builds instants via `DateTimeImmutable` (constructing the wall-clock value directly in the relevant `DateTimeZone`, then reading back the UTC epoch) rather than hand-rolling epoch arithmetic -- PHP's own offset handling is already correct, unlike JS, which needed a hand-written floor-division helper to get pre-epoch instants right.
Table of Contents
Constants
- DATE_RE : mixed = '/^(\d{4})-(\d{2})-(\d{2})$/'
- DURATION_RE : mixed = '/^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)...
- OFFSET_RE : mixed = '/^([+-])(\d{2}):(\d{2})$/'
- TIME_RE : mixed = '/^(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,6}))?$/'
Methods
- formatDate() : string
- formatDuration() : string
- formatInstant() : string
- formatOffsetDateTime() : string
- formatTime() : string
- parseDate() : DXNDate
- parseDuration() : DXNDuration
- parseInstant() : DXNTimestamp
- `~U[YYYY-MM-DD HH:MM:SSZ]` -- date and time separated by one literal space, `Z` mandatory.
- parseOffsetDateTime() : DXNDateTime
- `YYYY-MM-DDTHH:MM:SS(.ffffff)?(Z|±HH:MM)` -- RFC 3339 separator, offset required (`Z` accepted defensively).
- parseTime() : DXNTime
- __construct() : mixed
- buildDateTimeImmutable() : DateTimeImmutable
- extractTime() : DXNTime
- formatOffsetMinutes() : string
- formatSeconds() : string
- intOrNull() : int|null
- offsetTimeZone() : DateTimeZone
Constants
DATE_RE
private
mixed
DATE_RE
= '/^(\d{4})-(\d{2})-(\d{2})$/'
DURATION_RE
private
mixed
DURATION_RE
= '/^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/'
OFFSET_RE
private
mixed
OFFSET_RE
= '/^([+-])(\d{2}):(\d{2})$/'
TIME_RE
private
mixed
TIME_RE
= '/^(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,6}))?$/'
Methods
formatDate()
public
static formatDate(DXNDate $date) : string
Parameters
- $date : DXNDate
Return values
stringformatDuration()
public
static formatDuration(DXNDuration $d) : string
Parameters
- $d : DXNDuration
Return values
stringformatInstant()
public
static formatInstant(DXNTimestamp $ts) : string
Parameters
- $ts : DXNTimestamp
Return values
stringformatOffsetDateTime()
public
static formatOffsetDateTime(DXNDateTime $dt) : string
Parameters
- $dt : DXNDateTime
Return values
stringformatTime()
public
static formatTime(DXNTime $time) : string
Parameters
- $time : DXNTime
Return values
stringparseDate()
public
static parseDate(string $text) : DXNDate
Parameters
- $text : string
Return values
DXNDateparseDuration()
public
static parseDuration(string $text) : DXNDuration
Parameters
- $text : string
Return values
DXNDurationparseInstant()
`~U[YYYY-MM-DD HH:MM:SSZ]` -- date and time separated by one literal space, `Z` mandatory.
public
static parseInstant(string $inner) : DXNTimestamp
Parameters
- $inner : string
Return values
DXNTimestampparseOffsetDateTime()
`YYYY-MM-DDTHH:MM:SS(.ffffff)?(Z|±HH:MM)` -- RFC 3339 separator, offset required (`Z` accepted defensively).
public
static parseOffsetDateTime(string $text) : DXNDateTime
Parameters
- $text : string
Return values
DXNDateTimeparseTime()
public
static parseTime(string $text) : DXNTime
Parameters
- $text : string
Return values
DXNTime__construct()
private
__construct() : mixed
buildDateTimeImmutable()
private
static buildDateTimeImmutable(DXNDate $date, DXNTime $time, DateTimeZone $tz) : DateTimeImmutable
Parameters
Return values
DateTimeImmutableextractTime()
private
static extractTime(DateTimeImmutable $d) : DXNTime
Parameters
- $d : DateTimeImmutable
Return values
DXNTimeformatOffsetMinutes()
private
static formatOffsetMinutes(int $offsetMinutes) : string
Parameters
- $offsetMinutes : int
Return values
stringformatSeconds()
private
static formatSeconds(int $microseconds) : string
Parameters
- $microseconds : int
Return values
stringintOrNull()
private
static intOrNull(string $s) : int|null
Parameters
- $s : string
Return values
int|nulloffsetTimeZone()
private
static offsetTimeZone(int $offsetMinutes) : DateTimeZone
Parameters
- $offsetMinutes : int