2017 © Pedro Peláez
 

library timerange

Compare and loop time ranges in PHP.

image

jarnstedt/timerange

Compare and loop time ranges in PHP.

  • Friday, June 26, 2015
  • by jarnstedt
  • Repository
  • 3 Watchers
  • 5 Stars
  • 1,141 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 5 Versions
  • 1 % Grown

The README.md

TimeRange SensioLabsInsight

Compare and loop time ranges in PHP., (*1)

Install

For manual install copy timerange.php to your project., (*2)

Install with Composer:, (*3)

composer.phar require jarnstedt/timerange

Examples

Creating a TimeRange object

use TimeRange;

// Create a new TimeRange
$timeRange1 = new TimeRange('2013-03-31 00:00:00', '2013-04-01 01:09:00');

// You can also use PHP DateTime objects
$start = new DateTime('2000-01-01');
$end = new DateTime('2000-01-05');
$timeRange2 = new TimeRange($start, $end);

Looping TimeRange

TimeRange supports looping minutes, hours, days and months., (*4)

// Echo all days in time range
foreach ($timeRange1->getDays() as $datetime) {
  echo $datetime->format('Y-m-d')."<br>";
}

// Echo every other day in time range backwards
foreach ($timeRange1->getDays(2, TimeRange::BACKWARD) as $datetime) {
  echo $datetime->format('Y-m-d')."<br>";
}

// Echo all minutes
foreach ($timeRange1->getMinutes() as $datetime) {
  echo $datetime->format('Y-m-d H:i')."<br>";
}

Check if two TimeRanges overlap

$timeRange1 = new TimeRange('2013-03-31 00:00', '2013-04-01 01:09');
$timeRange2 = new TimeRange('2013-01-01 12:30', '2013-01-05 14:00');

if ($timeRange1->overlaps($timeRange2)) {
  echo "Ranges overlap";
}

// Check if date overlaps the TimeRange
if ($timeRange1->overlaps("2013-04-01", TimeRange::DAY)) {
  ...
}

Changing start or end of the range

$timeRange = new TimeRange('2013-03-31 00:00', '2013-04-01 01:09');
$timeRange->setStart('2013-02-28');
$timeRange->setEnd('2013-03-03');

Running unit tests

Download phpunit from http://phpunit.de/ and in project directory run:, (*5)

php phpunit.phar

The Versions

26/06 2015

dev-master

9999999-dev https://github.com/jarnstedt/TimeRange

Compare and loop time ranges in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Joonas Järnstedt
by Juhani Viitanen

date range time datetime period compare

28/10 2014

1.0.3

1.0.3.0 https://github.com/jarnstedt/TimeRange

Compare and loop time ranges in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Joonas Järnstedt
by Juhani Viitanen

date range time datetime period compare

28/10 2014

1.0.2

1.0.2.0 https://github.com/jarnstedt/TimeRange

Compare and loop time ranges in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Joonas Järnstedt
by Juhani Viitanen

date range time datetime period compare

08/10 2014

1.0.1

1.0.1.0 https://github.com/jarnstedt/TimeRange

Compare and loop time ranges in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Joonas Järnstedt
by Juhani Viitanen

date range time datetime period compare

19/05 2014

1.0.0

1.0.0.0 https://github.com/jarnstedt/TimeRange

Compare and loop time ranges in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Joonas Järnstedt
by Juhani Viitanen

date range time datetime period compare