2017 © Pedro Peláez
 

library date-timespan

Collection of PHP classes to work with timespans.

image

smhg/date-timespan

Collection of PHP classes to work with timespans.

  • Thursday, November 16, 2017
  • by smhg
  • Repository
  • 1 Watchers
  • 5 Stars
  • 3,134 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 14 Versions
  • 0 % Grown

The README.md

date-timespan Build status

Collection of PHP classes to work with timespans., (*1)

It differs from DatePeriod in that it only defines a timespan/period by a start and end date. It offers algebraic methods to manipulate a timespan or a collection of them. Convert it to a DatePeriod passing a DateInterval to toPeriod() when you need to iterate over it., (*2)

Installation

$ composer require smhg/date-timespan

Methods

Timespan

use Timespan\Timespan;

$start = new DateTime('last monday');
$end = clone $start;
$end->modify('+1 week');

$timespan = new Timespan($start, $end);

contains(DateTime)

Returns whether the timespan contains a date., (*3)

overlaps(Timespan)

Returns whether the timespan overlaps with another timespan., (*4)

diff(Timespan)

Returns a collection of timespans (pieces of the original timespan) which do not appear in another timespan., (*5)

merge(Timespan)

Returns a collection with the merged timespan or both timespans when a merge was not possible., (*6)

trim(DateTime, DateTime)

Returns a new timespan fitting within the passed boundaries or null if no time remains., (*7)

compare(Timespan)

Returns whether the timespan occurs before, together or after another timespan., (*8)

toPeriod(DateInterval)

Converts the timespan to a DatePeriod using an interval., (*9)

__toString()

Converts the timespan to a string in ISO 8601 time interval format., (*10)

toArray()

Converts the timespan to an array with a single interval element containing the toString representation., (*11)

Collection

use Timespan\Timespan;
use Timespan\Collection;

$collection = new Collection();
$collection[] = new Timespan(...);

sort()

Sorts the collection based on the start of each timespan., (*12)

compress()

Joins timespans in the collection if they overlap. Also sorts the result., (*13)

merge()

Merges the collection with another collection. Also compresses the result., (*14)

The Versions

16/11 2017

dev-master

9999999-dev

Collection of PHP classes to work with timespans.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Avatar smhg

timespan

16/11 2017

v1.0.0

1.0.0.0

Collection of PHP classes to work with timespans.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Avatar smhg

timespan

02/06 2016

v0.2.3

0.2.3.0

Collection of PHP classes to work with timespans.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar smhg

timespan

03/08 2015

v0.2.2

0.2.2.0

Timespan classes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar smhg

timespan

23/10 2014

v0.2.1

0.2.1.0

Timespan classes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar smhg

timespan

21/10 2014

v0.2.0

0.2.0.0

Timespan classes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar smhg

timespan

06/05 2014

0.1.7

0.1.7.0

Timespan classes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar smhg

timespan

06/05 2014

0.1.6

0.1.6.0

Timespan classes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar smhg

timespan

12/03 2014

0.1.5

0.1.5.0

Timespan classes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar smhg

timespan

10/03 2014

0.1.4

0.1.4.0

Timespan classes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar smhg

timespan

09/03 2014

0.1.3

0.1.3.0

Timespan classes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar smhg

timespan

09/03 2014

0.1.2

0.1.2.0

Timespan classes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar smhg

timespan

09/03 2014

0.1.1

0.1.1.0

Timespan classes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar smhg

timespan

08/03 2014

0.1.0

0.1.0.0

Timespan classes

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Avatar smhg

timespan