Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
SystemClock
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 now
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace LambdaTwelve\OneRecord\Server;
6
7use DateTimeImmutable;
8use DateTimeZone;
9use Psr\Clock\ClockInterface;
10
11/**
12 * The real clock, in UTC, at millisecond precision. JSON-LD timestamps are
13 * written with milliseconds (Literal::dateTime), so a finer clock would make
14 * a stored document differ from the instant the server computed; truncating
15 * here keeps every store, in memory or in a database, byte-identical.
16 * Hosts with a PSR-20 clock of their own should truncate the same way.
17 */
18final class SystemClock implements ClockInterface
19{
20    public function now(): DateTimeImmutable
21    {
22        $now = new DateTimeImmutable('now', new DateTimeZone('UTC'));
23
24        return $now->setTime((int) $now->format('G'), (int) $now->format('i'), (int) $now->format('s'), (int) $now->format('v') * 1000);
25    }
26}