2017 © Pedro Peláez
 

library gotime

Golang-like time class(es) for PHP 7.0+

image

dcarbone/gotime

Golang-like time class(es) for PHP 7.0+

  • Friday, June 22, 2018
  • by dcarbone
  • Repository
  • 1 Watchers
  • 1 Stars
  • 720 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 236 % Grown

The README.md

gotime

Golang-like time class(es) for PHP 7.3+, (*1)

Tests, (*2)

Desc

The goal of this lib is to achieve near-enough (as determined by me) api equivalency in PHP to the GoLang Time package, as basically it is just better than PHP's., (*3)

Classes

Duration

The Duration class is designed to emulate the golang time.Duration type., (*4)

There are 2 ways to construct a Duration class:, (*5)

use \DCarbone\Go\Time;

$d = new Time\Duration(5 * Time::Second);
// produces a Duration with an internal value of 5e9;

$d = Time::ParseDuration('5s');
// produces a Duration with an internal value of 5e9;

Internally the "duration" is represented as an integer, allow for much fun., (*6)

Serialization

Assuming $dt = new Time\Duration(5 * Time::Second);:, (*7)

Type Exec Output
JSON echo json_encode($dt); 5000000000
string echo (string)$dt; 5s;

DateInterval

DateInterval pretty much sucks. I have created my own DateInterval and IntervalSpec classes to help alleviate this., (*8)

These provide Duration the ability to create an interval for use with the standard DateTime::add and DateTime::sub methods as such:, (*9)

$dt = new \DateTime();
echo "{$dt->format('H:i:s')}\n";

$d = new Time\Duration(5 * Time::Second);
$dt->add($d->DateInterval());
echo "{$dt->format('H:i:s')}\n";

// 16:03:37
// 16:03:42

Time

The Time class is designed to BARELY emulate the golang time.Time type. It's basically DateTime with stuff on it. I consider it to be in a "beta" state., (*10)

There are 2 basic ways to construct a Time class:, (*11)

use DCarbone\Go\Time;

// Returns an instance of Time\Time with an internal time of the unix epoch 
$t = Time::New();

// Returns an instance of Time\Time with an internal time of whenever you constructed it. 
$t = Time::Now();

The Versions

22/06 2018

dev-master

9999999-dev https://github.com/dcarbone/gotime

Golang-like time class(es) for PHP 7.0+

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Daniel Carbone

22/06 2018

0.3.0

0.3.0.0 https://github.com/dcarbone/gotime

Golang-like time class(es) for PHP 7.0+

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Daniel Carbone

08/03 2018

0.2.4

0.2.4.0 https://github.com/dcarbone/gotime

Golang-like time class(es) for PHP 7.0+

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Daniel Carbone

05/03 2018

0.2.3

0.2.3.0 https://github.com/dcarbone/gotime

Golang-like time class(es) for PHP 7.0+

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Daniel Carbone

04/03 2018

0.2.2

0.2.2.0 https://github.com/dcarbone/gotime

Golang-like time class(es) for PHP 7.0+

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Daniel Carbone

01/03 2018

0.2.1

0.2.1.0 https://github.com/dcarbone/gotime

Golang-like time class(es) for PHP 7.0+

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Daniel Carbone

22/02 2018

0.2.0

0.2.0.0 https://github.com/dcarbone/gotime

Golang-like time class(es) for PHP 7.0+

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Daniel Carbone

12/12 2017

0.1.2

0.1.2.0 https://github.com/dcarbone/gotime

Golang-like time class(es) for PHP 7.0+

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Daniel Carbone

12/12 2017

0.1.1

0.1.1.0 https://github.com/dcarbone/gotime

Golang-like time class(es) for PHP 7.0+

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Daniel Carbone

11/12 2017

0.1.0

0.1.0.0 https://github.com/dcarbone/gotime

Golang-like time class(es) for PHP 7.0+

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-gmp *

 

The Development Requires

by Daniel Carbone