The Datepoint class

The Datepoint class is introduced in version 4.2.

A datepoint is a position in time expressed as a DateTimeImmutable object.

The Datepoint class is introduced to ease Datepoint manipulation. This class extends PHP’s DateTimeImmutable class by adding a new named constructor and several getter methods.

Named constructor


public Datepoint::create($datepoint): self

Returns a Datepoint object or throws:


Because we are using PHP's parser, values exceeding ranges will be added to their parent values.

If no timezone information is given, the returned Datepoint object will use the current timezone.


Using the $datepoint argument

use League\Period\Datepoint;

Datepoint::create('yesterday'); // returns new Datepoint('yesterday')
Datepoint::create('2018');      // returns new Datepoint('@2018')
Datepoint::create(2018);        // returns new Datepoint('@2018')
Datepoint::create(new DateTime('2018-10-15'));  // returns new Datepoint('2018-10-15')
Datepoint::create(new DateTimeImmutable('2018-10-15'));  // returns new Datepoint('2018-10-15')

Accessing calendar interval

Once you’ve got a Datepoint instantiated object, you can access a set of calendar type interval using the following methods.

public Datepoint::getSecond(): Period;
public Datepoint::getMinute(): Period
public Datepoint::getHour(): Period
public Datepoint::getDay(): Period
public Datepoint::getIsoWeek(): Period
public Datepoint::getMonth(): Period
public Datepoint::getQuarter(): Period
public Datepoint::getSemester(): Period
public Datepoint::getYear(): Period
public Datepoint::getIsoYear(): Period

For each a these methods a Period object is returned with:


use League\Period\Datepoint;

$datepoint = new Datepoint('2018-06-18 08:35:25');
$hour = $datepoint->getHour();
// new Period('2018-06-18 08:00:00', '2018-06-18 09:00:00');
$month = $datepoint->getMonth();
// new Period('2018-06-01 00:00:00', '2018-07-01 00:00:00');
$month->contains($datepoint); // true
$hour->contains($datepoint); // true
$month->contains($hour); // true

Relational method against interval

Since version 4.5

A datepoint can also be evaluated in relation to a given interval.
The following methods all share the same signature:

public function method(Period $interval): bool

where method is one of the basic relation between a datepoint and an interval.


use League\Period\Datepoint;
use League\Period\Period;

$datepoint = Datepoint::create('2018-01-18 10:00:00');
    Period::after($datepoint, '3 minutes', Period::EXCLUDE_START_INCLUDE_END)
); //  true

    Period::after($datepoint, '3 minutes', Period::INCLUDE_ALL)
); // false

    Period::before('2018-01-13 23:34:28', '3 minutes', Period::INCLUDE_START_EXCLUDE_END)
);  // true