src
1 year ago
ChangeLog.md
1 year ago
LICENSE
1 year ago
README.md
1 year ago
composer.json
1 year ago
README.md
42 lines
| 1 | # sebastian/comparator |
| 2 | |
| 3 | [](https://github.com/sebastianbergmann/comparator/actions](https://github.com/sebastianbergmann/comparator/actions](https://github.com/sebastianbergmann/comparator/actions) |
| 4 | [](https://shepherd.dev/github/sebastianbergmann/comparator](https://shepherd.dev/github/sebastianbergmann/comparator](https://shepherd.dev/github/sebastianbergmann/comparator) |
| 5 | |
| 6 | This component provides the functionality to compare PHP values for equality. |
| 7 | |
| 8 | ## Installation |
| 9 | |
| 10 | You can add this library as a local, per-project dependency to your project using [](https://getcomposer.org/Composer](https://getcomposer.org/](https://getcomposer.org/): |
| 11 | |
| 12 | ``` |
| 13 | composer require sebastian/comparator |
| 14 | ``` |
| 15 | |
| 16 | If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency: |
| 17 | |
| 18 | ``` |
| 19 | composer require --dev sebastian/comparator |
| 20 | ``` |
| 21 | |
| 22 | ## Usage |
| 23 | |
| 24 | ```php |
| 25 | <?php |
| 26 | use SebastianBergmann\Comparator\Factory; |
| 27 | use SebastianBergmann\Comparator\ComparisonFailure; |
| 28 | |
| 29 | $date1 = new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')); |
| 30 | $date2 = new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/Chicago')); |
| 31 | |
| 32 | $factory = new Factory; |
| 33 | $comparator = $factory->getComparatorFor($date1, $date2); |
| 34 | |
| 35 | try { |
| 36 | $comparator->assertEquals($date1, $date2); |
| 37 | print "Dates match"; |
| 38 | } catch (ComparisonFailure $failure) { |
| 39 | print "Dates don't match"; |
| 40 | } |
| 41 | ``` |
| 42 |