The Postgres database supports ranges. This package provides capabilities to parse or build tstzranges for Postgres databases. This package attempts to fully support all the features of the tstzrange type. We made an exception for null values, which are interpreted as "infinity".
You can install the package via composer:
composer require inthere/datetime-range
$parser = new Parser(
'["2015-08-14 16:07:28.956968+02","2018-08-14 16:07:28.956968+02"]',
new DateTimeZone('UTC')
);
$dateTimeRange = $parser->parse();
This returns a DateTimeRange
object, which can provide the lower and upper range:
$lowerRange = $dateTimeRange->getLowerRange();
$upperRange = $dateTimeRange->getUpperRange();
A Range
object will be returned which contains the date, the boundary and which knows if the range is "infinity":
$lowerRange->isInfinity();
// returns a boolean
$lowerRange->getDateTime();
// returns a datetime object or null if infinity
$lowerRange->getBoundary();
// returns a boundary object
The Boundary
object determines if the range is inclusive [] or exclusive () and if the range is lower or upper:
$boundary = $lowerRange->getBoundary();
$boundary->isLower();
// returns a boolean (true = lower, false = upper)
$boundary->isInclusive();
// returns a boolean (true = inclusive, false = exclusive)
$ vendor/bin/phpunit
Contributions are welcome. We accept contributions via pull requests on Github.
The MIT License (MIT). Please see the License File for more information.
InThere - "The training Through Gaming Company" - speeds up training your team and change processes by providing a micro-training concept based on serious games.