Core\Time\Instant
One exact point in time, the same everywhere in the world. It has no time zone and no calendar. Core\Time::now, Core\Time\Instant::fromEpoch and Core\Time\Instant::fromIso return one. plus, minus and since do exact arithmetic with a Duration, and in shows the instant on a zone's calendar.
An Instant is a point on the timeline. It has no calendar and no zone. Instant::fromIso reads an RFC 3339 timestamp such as 2024-03-01T12:00:00Z. Instant::fromEpoch builds one from seconds since 1 January 1970. Core\Time::now() returns the current instant.
An Instant has an epoch count and a text form in UTC. ->in($zone) gives its date and time of day in a zone, as a DateTime. It moves only by an exact Duration: plus(36h) is always thirty-six hours. since returns the exact time between two instants. A step in days or months is taken on the DateTime that ->in($zone) returns. compareTo orders two instants. The <, > and <=> operators do not compile on an Instant.
<?nvsvar $start = Core\Time\Instant::fromIso('2024-03-01T12:00:00Z');echo $start->toIso(), "\n";echo $start->toEpochSeconds(), "\n";echo $start->toEpochMillis(), "\n";
var $end = $start->plus(36h);echo $end->toIso(), "\n";echo $end->since($start), "\n";echo $start->minus(30m)->toIso(), "\n";echo $start->compareTo($end), "\n";
echo $start->in('Asia/Tokyo')->format('yyyy-MM-dd HH:mm'), "\n";echo Core\Time\Instant::fromEpoch(1709294400, { nanoseconds: 500000000 })->toIso(), "\n";2024-03-01T12:00:00Z170929440017092944000002024-03-03T00:00:00Z1d12h2024-03-01T11:30:00Z-12024-03-01 21:002024-03-01T12:00:00.5ZReturned by
You get a Core\Time\Instant from these methods:
Core\Db\Row::instantCore\FileTransfer\Entry::modifiedAtCore\Http\TlsInfo::expiryCore\IO::modifiedAtCore\IO\Metadata::modifiedAtCore\Ldap\Entry::instantCore\Router\Match::parameterCore\Time::nowCore\Time\DateTime::toInstant
Members
11 members.
| Member | Signature |
|---|---|
fromEpoch | fromEpoch(int $seconds, { nanoseconds?: uint }): Core\Time\Instant |
fromIso | fromIso(string $text): Core\Time\Instant |
in | in(Core\Time\Zone $zone): Core\Time\DateTime |
toEpochSeconds | toEpochSeconds(): int |
toEpochMillis | toEpochMillis(): int |
toEpochMicros | toEpochMicros(): int |
plus | plus(Core\Time\Duration $d): Core\Time\Instant |
minus | minus(Core\Time\Duration $d): Core\Time\Instant |
since | since(Core\Time\Instant $earlier): Core\Time\Duration |
compareTo | compareTo(Core\Time\Instant $other): int |
toIso | toIso(): string |
