Skip to content

From v3 to v4

All namespaces are relative to \Innmind\TimeContinuum\.

These are the main changes, for an extensive list of changes go to the changelog.

Clocks

Live clock

$clock = new Earth\Clock;
$clock = Clock::live();

Logger

$clock = new Logger\Clock(
    new Earth\Clock,
    /* an instance of Psr\Log\LoggerInterface */
);
$clock = Clock::logger(
    Clock::live(),
    /* an instance of Psr\Log\LoggerInterface */
);

Frozen

$clock = new Earth\FrozenClock(
    new Earth\PointInTime\PointInTime('some date'),
);
$clock = Clock::live()
    ->at('some date', Format::iso8601())
    ->match(
        Clock::frozen(...),
        static fn() => throw new \LogicException('Use a valid date'),
    );

Timezones

$clock = new Earth\Clock(
    new Earth\Timezone\Europe\Paris,
);
$clock = Clock::live()->switch(
    static fn(Timezones $timezones) => $timezones
        ->europe()
        ->paris(),
);

Access point in time offset

$clock->now()->timezone()->hours();
$clock->now()->timezone()->minutes();
$clock->now()->offset()->hours();
$clock->now()->offset()->minutes();

Modify point in time offset

$clock->now()->changeTimezone(new Earth\Timezone\UTC(2, 0));
$clock->now()->changeOffset(Offset::plus(2, 0));

Periods

new Earth\Period\Year(42);
new Earth\Period\Month(42);
new Earth\Period\Day(42);
new Earth\Period\Hour(42);
new Earth\Period\Minute(42);
new Earth\Period\Second(42);
new Earth\Period\Millisecond(42);
Period::year(42);
Period::month(42);
Period::day(42);
Period::hour(42);
Period::minute(42);
Period::second(42);
Period::millisecond(42);

Formats

$clock->now()->format(new Earth\Format\ISO8601);
$clock->now()->format(Format::iso8601());

Elapsed periods

$elapsed = /* any instance of ElapsedPeriod */
$milliseconds = $elapsed->milliseconds();
$elapsed = /* any instance of ElapsedPeriod */
$period = $elapsed->asPeriod();
$milliseconds = Period\Value::day->seconds($period->days());
$milliseconds += Period\Value::hour->seconds($period->hours());
$milliseconds += Period\Value::minute->seconds($period->minutes());
$milliseconds *= 1_000;
$milliseconds += $period->milliseconds();