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