Skip to content

Provides capabilities to parse or build tstzranges for Postgres databases

License

Notifications You must be signed in to change notification settings

4GrowthBV/datetime-range

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DateTimeRange

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".

Installation

You can install the package via composer:

composer require inthere/datetime-range

Usage

$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)

Tests

$ vendor/bin/phpunit

Contributors

Contributions are welcome. We accept contributions via pull requests on Github.

License

The MIT License (MIT). Please see the License File for more information.

About InThere

InThere - "The training Through Gaming Company" - speeds up training your team and change processes by providing a micro-training concept based on serious games.

About

Provides capabilities to parse or build tstzranges for Postgres databases

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages