1. Go to this page and download the library: Download baldinof/clock library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
baldinof / clock example snippets
use Baldinof\Clock\Clock;
$now = Clock::now();
assert($now instanceof \DateTimeImmutable);
use Baldinof\Clock\Clock;
use Ramsey\Uuid\Uuid;
final class User
{
private $id;
private $createdAt;
private $name;
public function __construct(string $name)
{
$this->id = Uuid::uuid4();
$this->createdAt = Clock::now();
$this->name = $name;
}
// Getters...
}
use Baldinof\Clock\Testing\FrozenClockTrait;
use Baldinof\Clock\Clock;
use PHPUnit\Framework\TestCase;
final class UserTest extends TestCase
{
use FrozenClockTrait;
public function test_it_is_initialized_with_current_time()
{
$user = new User("John");
$this->assertEquals(Clock::now(), $user->createdAt());
}
}
use Baldinof\Clock\Testing\FrozenClockTrait;
use Baldinof\Clock\Clock;
use PHPUnit\Framework\TestCase;
final class UserTest extends TestCase
{
use FrozenClockTrait;
public function my_function()
{
// Set the clock at a specified time.
$this->freezeClock(new \DateTimeImmutable('2000-01-01'));
// Add an hour to the clock.
$this->modifyClock('+1 h');
// Reset the clock.
$this->restoreSystemClock();
}
}
use Baldinof\Clock\Clock;
use Baldinof\Clock\SystemClock;
// Change the clock implementation
Clock::set(SystemClock::forTimeZone('UTC'));
// or change the default timezone
date_default_timezone_set('UTC');
use Baldinof\Clock\Clock;
use Baldinof\Clock\ClockInterface;
return function (ContainerConfigurator $container) {
$services = $container->services();
$services
->set(ClockInterface::class)
->factory([Clock::class, 'get']);
};
// In a service provider
$this->app->instance(ClockInterface::class, Clock::get());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.