The League of Extraordinary Packages

Our Packages:

Presented by The League of Extraordinary Packages


Time range API for PHP

$ composer require league/period




use League\Period\Period;

$period = Period::createFromDuration('2014-10-03 08:12:37', 3600);
$start = $period->getStartDate();
$end   = $period->getEndDate();
$duration  = $period->getDateInterval();
$altPeriod = $period->endingOn('2014-12-03');
$period->contains($altPeriod); //return false;
$altPeriod->durationGreaterThan($period); //return true;


Period is PHP's missing Time Range class. It is based on Resolving Feature Envy in the Domain by Mathias Verraes and extends the concept to cover all basic operations regarding time ranges.

  1. Treats Time Range as immutable value objects

  2. Exposes many named constructors to ease time range creation

  3. Covers all basic manipulations related to time range

  4. Framework-agnostic


Current Stable Release

League\Period 3.0

  • Requires: PHP >= 5.5.0
  • Release Date: 2015-09-02
  • Supported Until: TBD

Full Documentation

No longer Supported

League\Period 2.0

  • Requires: PHP >= 5.3.0
  • Release Date: 2014-10-15
  • Supported Until: 2016-03-02

Once a new major version is released, the previous stable release remains supported for six (6) more months through patches and/or security fixes.


League\Period was created by Ignace Nyamagana Butera. Find him on Twitter at @nyamsprod.