php-dextrin

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
string

formatTime()

public static formatTime(DXNTime $time) : string
Parameters
$time : DXNTime
Return values
string

parseInstant()

`~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
DXNTimestamp

parseOffsetDateTime()

`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
DXNDateTime

__construct()

private __construct() : mixed

buildDateTimeImmutable()

private static buildDateTimeImmutable(DXNDate $date, DXNTime $time, DateTimeZone $tz) : DateTimeImmutable
Parameters
$date : DXNDate
$time : DXNTime
$tz : DateTimeZone
Return values
DateTimeImmutable

extractTime()

private static extractTime(DateTimeImmutable $d) : DXNTime
Parameters
$d : DateTimeImmutable
Return values
DXNTime

formatOffsetMinutes()

private static formatOffsetMinutes(int $offsetMinutes) : string
Parameters
$offsetMinutes : int
Return values
string

formatSeconds()

private static formatSeconds(int $microseconds) : string
Parameters
$microseconds : int
Return values
string

intOrNull()

private static intOrNull(string $s) : int|null
Parameters
$s : string
Return values
int|null

offsetTimeZone()

private static offsetTimeZone(int $offsetMinutes) : DateTimeZone
Parameters
$offsetMinutes : int
Return values
DateTimeZone
On this page

Search results