oprokidnev / partial-date
Partial date with compare support
dev-master / 0.1.x-dev
2017-09-12 06:10 UTC
Requires
- php: ^7.1.0
Requires (Dev)
- nikic/php-parser: ^3.0.4
- phpunit/phpunit: ^5.6.4
- phpunit/phpunit-mock-objects: ^3.4.1
- symfony/var-dumper: ^3.3
This package is auto-updated.
Last update: 2024-12-22 01:55:00 UTC
README
Supported date formats
Package supports dates, defined using the following formats:
H:i:s d.m.Y
(01:00:05 21.07.2017)H:i d.m.Y
(01:00 21.07.2017)H: d.m.Y
(01: 21.07.2017)d.m.Y
(21.07.2017)m.Y
(07.2017)Y
(2017)H:i:s
(01:00:05)H:i
(01:00)H:
(01:)
Comparison
Partially defined dates can be compared one with another. Basic usage example is:
<?php $partialDateA = new \Oprokidnev\PartialDate\PartialDate('2017'); $partialDateB = new \Oprokidnev\PartialDate\PartialDate('2018'); $partialDateA->compareTo($partialDateB); // -1 A is less than B $partialDateC = new \Oprokidnev\PartialDate\PartialDate('02.2017'); $partialDateD = new \Oprokidnev\PartialDate\PartialDate('2018'); $partialDateD->compareTo($partialDateC); // 1 D is greater than C try { $partialDateE = new \Oprokidnev\PartialDate\PartialDate('01.2017'); $partialDateF = new \Oprokidnev\PartialDate\PartialDate('2017'); $partialDateE->compareTo($partialDateF); } catch (\Oprokidnev\PartialDate\Exception\UnobviousResultException $ex) { echo 'Unobvious result'; }
Installation
composer require oprokidnev/partial-date
Contribution
composer create-project oprokidnev/partial-date --stability dev;
composer run tests