pekkis/clock

A very simple clock abstraction

v1.0.0 2015-07-23 07:56 UTC

This package is not auto-updated.

Last update: 2024-10-26 15:54:52 UTC


README

A really simple clock abstraction library for PHP.

Usage

<?php

namespace Pekkis\Clock\Example;

require_once __DIR__ . '/../vendor/autoload.php';

use Pekkis\Clock\ClockProvider;
use Pekkis\Clock\FixedClock;
use DateTime;

// Real system clock, returns actual time
$time = ClockProvider::getClock()->getTime();
var_dump($time);

// Fixed clock (for testing for example)
ClockProvider::setClock(new FixedClock(new DateTime('1978-03-21')));
$time = ClockProvider::getClock()->getTime();
var_dump($time);

// Get time as datetime object
$time = ClockProvider::getClock()->getDateTime();
var_dump($time->format('Y-m-d H:i:s'));