php-dextrin

DXNDateTime
in package
implements DXNValueInterface

FinalYes

DXN `datetime` (`@datetime "2026-10-20T14:30:00Z"`) -- an instant with its offset, `Z` for UTC (DXN.md §1.3). DXN 0.2's `timestamp`, a UTC instant, is one of these at offset zero (Jan, 2026-10-20). Mirrors `.dxnb`'s wire shape directly: the instant as nanoseconds since the epoch, and the offset it was written with, in minutes.

$epochNanoseconds is a PHP integer, 64 bits: it reaches from 1677 to 2262, and an instant outside that is refused (Nanos). DateTimeImmutable stops at the microsecond, so self::toDateTimeImmutable() drops what is finer, and self::fromDateTimeImmutable() is exact.

Table of Contents

Interfaces

DXNValueInterface
Implemented by every `DXN*` wrapper class -- the PHP analog of the `dxnType` string tag used for kind dispatch in the JS port, and of `Dextrin.Value`'s closed type union in the Elixir original. Native PHP values (`null`, `bool`, `int`, `float`, `string`, and `array` for `map`/`array`) never implement this; {@see Equality::kindOf()} handles those directly.

Constants

DXN_TYPE  : mixed = 'datetime'

Properties

$epochNanoseconds  : int
$offsetMinutes  : int

Methods

__construct()  : mixed
compareTo()  : int
Ordered by instant, whatever the offsets.
dxnType()  : string
The DXN type name this value represents, e.g. "symbol", "uuid".
equals()  : bool
The same instant at the same offset: one written at another offset is another value.
fromDateTimeImmutable()  : self
`$offsetMinutes` may be supplied explicitly -- `DateTimeImmutable` can't infer "the offset the caller means" any more than a plain instant can; it only knows the offset its own `DateTimeZone` carries, which this defaults to when not given.
fromNative()  : self
A native date, as the `datetime` it always means (DXNS.md §7): its instant, with the offset its own zone carries at that instant.
toDateTimeImmutable()  : DateTimeImmutable
The instant at its offset, to the microsecond.

Constants

Properties

$epochNanoseconds read-only

public int $epochNanoseconds

Methods

__construct()

public __construct(int $epochNanoseconds, int $offsetMinutes) : mixed
Parameters
$epochNanoseconds : int
$offsetMinutes : int
Tags
throws
InvalidArgumentException

for an offset of a day or more.

compareTo()

Ordered by instant, whatever the offsets.

public compareTo(mixed $other) : int
Parameters
$other : mixed
Return values
int

dxnType()

The DXN type name this value represents, e.g. "symbol", "uuid".

public dxnType() : string
Return values
string

equals()

The same instant at the same offset: one written at another offset is another value.

public equals(mixed $other) : bool
Parameters
$other : mixed
Return values
bool

fromDateTimeImmutable()

`$offsetMinutes` may be supplied explicitly -- `DateTimeImmutable` can't infer "the offset the caller means" any more than a plain instant can; it only knows the offset its own `DateTimeZone` carries, which this defaults to when not given.

public static fromDateTimeImmutable(DateTimeImmutable $date[, int|null $offsetMinutes = null ]) : self
Parameters
$date : DateTimeImmutable
$offsetMinutes : int|null = null
Tags
throws
InvalidArgumentException

outside the range 64 bits hold.

Return values
self

fromNative()

A native date, as the `datetime` it always means (DXNS.md §7): its instant, with the offset its own zone carries at that instant.

public static fromNative(DateTimeInterface $date) : self

A host value means the same DXN type with or without a schema, and a native date always has a zone, which datetime keeps.

Parameters
$date : DateTimeInterface
Tags
throws
InvalidArgumentException

outside the range 64 bits hold.

Return values
self

toDateTimeImmutable()

The instant at its offset, to the microsecond.

public toDateTimeImmutable() : DateTimeImmutable
Tags
throws
RuntimeException

when PHP cannot build it.

Return values
DateTimeImmutable
On this page

Search results