Files
DesignPatternsPHP/Behavioral/Strategy/DateComparator.php
Antonio Spinelli 2f7837927f merged from master
2014-04-15 22:07:48 -03:00

25 lines
431 B
PHP

<?php
namespace DesignPatterns\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;
} else {
return $aDate < $bDate ? -1 : 1;
}
}
}