mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-02-24 01:32:22 +01:00
25 lines
431 B
PHP
25 lines
431 B
PHP
<?php
|
|
|
|
namespace DesignPatterns\Behavioral\Strategy;
|
|
|
|
/**
|
|
* Class DateComparator.
|
|
*/
|
|
class DateComparator implements ComparatorInterface
|
|
{
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function compare($a, $b)
|
|
{
|
|
$aDate = new \DateTime($a['date']);
|
|
$bDate = new \DateTime($b['date']);
|
|
|
|
if ($aDate == $bDate) {
|
|
return 0;
|
|
}
|
|
|
|
return $aDate < $bDate ? -1 : 1;
|
|
}
|
|
}
|