2017 © Pedro Peláez
 

library clock

A simple wrapper for abstracting the system date

image

intriro/clock

A simple wrapper for abstracting the system date

  • Tuesday, March 20, 2018
  • by intriro
  • Repository
  • 2 Watchers
  • 0 Stars
  • 81 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 5 % Grown

The README.md

Clock

A simple clock abstraction library for PHP., (*1)

Motivation

The problem with DateTime instances is that they are not testable and mockable. They always rely on the system date and time. Therefore you should never directly create DateTime instances., (*2)

With the Clock interface you are able to switch implementations and therefore have control over the returned DateTime instances., (*3)

Installation

Install it using Composer., (*4)

composer require intriro/clock

Implementation

The Clock object provides access to the current date and time. Basically it is just a object which returns a DateTimeImmutable instance that represents the current date and time., (*5)

With a Clock interface you can always swap implementations and get DateTimeImmutable instances which don't rely on the system time., (*6)

The library ships with a Clock interface and three implementations., (*7)

SystemClock gives you access to the system date and time. It just returns new DateTimeImmutable('now') and it's the default implementation., (*8)

ShiftedSystemClock returns the system date and time that is shifted for a provided interval., (*9)

FixedClock returns a predefined fixed date and time., (*10)

Example


class Event { /** * @var DateTimeImmutable */ private $date; public function hasPassed(Clock $clock): bool { if ($this->clock->now() > $this->date) { return true; } return false;    } }

The Versions

20/03 2018

dev-master

9999999-dev

A simple wrapper for abstracting the system date

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Avatar alsar

20/03 2018

1.1.1

1.1.1.0

A simple wrapper for abstracting the system date

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Avatar alsar

16/03 2018

1.1.0

1.1.0.0

A simple wrapper for abstracting the system date

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Avatar alsar

19/09 2017

1.0.0

1.0.0.0

A simple wrapper for abstracting the system date

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Avatar alsar

20/12 2016

0.1.1

0.1.1.0

A simple wrapper for abstracting the system date

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Avatar alsar

20/12 2016

0.1.0

0.1.0.0

A simple wrapper for abstracting the system date

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Avatar alsar