Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

spaceonfire/clock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clock by spaceonfire

Latest Version on Packagist Software License Total Downloads Code Coverage

This component provides enhanced DateTime classes and Clock API implementations in PHP.

Install

Via Composer

$ composer require spaceonfire/clock

Usage

DateTime:

use spaceonfire\Clock\DateTimeImmutableValue;

$time = DateTimeImmutableValue::now();
// $time = DateTimeImmutableValue::from('2020-02-02 20:22:02');
// $time = DateTimeImmutableValue::from(3 * DateTimeImmutableValue::HOUR); // now + 3 hours

\assert($time instanceof \DateTimeImmutable);

echo (string)$time;
// 2020-02-02 20:22:02
echo \json_encode($time);
// 2020-02-02T20:22:02+00:00

Clock:

use spaceonfire\Clock\FrozenClock;
use spaceonfire\Clock\SystemClock;

$clock = new FrozenClock(SystemClock::fromUTC());
$startedAt = $clock->now();
\sleep(5);
$finishedAt = $clock->now();
\assert($startedAt === $finishedAt);

$clock->reset();

Change log

Please see CHANGELOG for more information on what has changed recently.

Contributing

Report issues and send Pull Requests in the main spaceonfire repository. Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Credits

License

The MIT License (MIT). Please see License File for more information.