mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-31 04:00:18 +02:00
merged from master
This commit is contained in:
@@ -12,8 +12,8 @@ class DateComparator implements ComparatorInterface
|
||||
*/
|
||||
public function compare($a, $b)
|
||||
{
|
||||
$aDate = strtotime($a['date']);
|
||||
$bDate = strtotime($b['date']);
|
||||
$aDate = new \DateTime($a['date']);
|
||||
$bDate = new \DateTime($b['date']);
|
||||
|
||||
if ($aDate == $bDate) {
|
||||
return 0;
|
||||
|
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace DesignPatterns\Strategy;
|
||||
|
||||
$elements = array(
|
||||
array(
|
||||
'id' => 2,
|
||||
'date' => '2011-01-01',
|
||||
),
|
||||
array(
|
||||
'id' => 1,
|
||||
'date' => '2011-02-01'
|
||||
)
|
||||
);
|
||||
|
||||
$collection = new ObjectCollection($elements);
|
||||
$collection->setComparator(new IdComparator());
|
||||
$collection->sort();
|
||||
|
||||
$collection->setComparator(new DateComparator());
|
||||
$collection->sort();
|
Reference in New Issue
Block a user