Skip to content

Commit

Permalink
Optimize PR #902 (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sommerregen authored and flaviocopes committed Jun 16, 2016
1 parent f8964ab commit f845943
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions system/src/Grav/Common/Page/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,32 +273,18 @@ public function dateRange($startDate, $endDate = false, $field = false)
$end = $endDate ? Utils::date2timestamp($endDate) : false;

$date_range = [];
foreach ($this->items as $path => $slug) {
$page = $this->pages->get($path);
if ($page !== null) {
$date = $field ? strtotime($page->value($field)) : $page->date();

if ($end) {
foreach ($this->items as $path => $slug) {
$page = $this->pages->get($path);
if ($page !== null) {
$date = $field ? strtotime($page->value($field)) : $page->date();

if ($date >= $start && $date <= $end) {
$date_range[$path] = $slug;
}
}
}
} else {
foreach ($this->items as $path => $slug) {
$page = $this->pages->get($path);
if ($page !== null) {
$date = $field ? strtotime($page->value($field)) : $page->date();

if ($date >= $start) {
$date_range[$path] = $slug;
}
if ($date >= $start && (!$end || $date <= $end)) {
$date_range[$path] = $slug;
}
}
}

$this->items = $date_range;

return $this;
}

Expand Down

0 comments on commit f845943

Please sign in to comment.