Browse Source

update the DateTime formatting

to occurs after the callback has been applied
Anto 10 years ago
parent
commit
2fc66e7910
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/Collection/Iterator/SortIterator.php

+ 3 - 3
src/Collection/Iterator/SortIterator.php

@@ -67,10 +67,10 @@ class SortIterator extends Collection
         $callback = $this->_propertyExtractor($callback);
         $results = [];
         foreach ($items as $key => $value) {
-            if ($value instanceof \DateTime && $type === SORT_NUMERIC) {
-                $value = $value->format('U');
-            }
             $results[$key] = $callback($value);
+            if ($results[$key] instanceof \DateTime && $type === SORT_NUMERIC) {
+                $results[$key] = $results[$key]->format('U');
+            }
         }
 
         $dir === SORT_DESC ? arsort($results, $type) : asort($results, $type);