You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB

3 years ago
  1. # sebastian/comparator
  2. [![CI Status](https://github.com/sebastianbergmann/comparator/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/comparator/actions)
  3. [![Type Coverage](https://shepherd.dev/github/sebastianbergmann/comparator/coverage.svg)](https://shepherd.dev/github/sebastianbergmann/comparator)
  4. This component provides the functionality to compare PHP values for equality.
  5. ## Installation
  6. You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
  7. ```
  8. composer require sebastian/comparator
  9. ```
  10. 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:
  11. ```
  12. composer require --dev sebastian/comparator
  13. ```
  14. ## Usage
  15. ```php
  16. <?php
  17. use SebastianBergmann\Comparator\Factory;
  18. use SebastianBergmann\Comparator\ComparisonFailure;
  19. $date1 = new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York'));
  20. $date2 = new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/Chicago'));
  21. $factory = new Factory;
  22. $comparator = $factory->getComparatorFor($date1, $date2);
  23. try {
  24. $comparator->assertEquals($date1, $date2);
  25. print "Dates match";
  26. } catch (ComparisonFailure $failure) {
  27. print "Dates don't match";
  28. }
  29. ```