$this->last, 'daily' => $this->daily, 'weekly' => $this->weekly, 'monthly' => $this->monthly]; } /** * @param array $snapshots id => unix time * @return array> id => reasons it is kept (ids not in the result are removed) */ public function keep(array $snapshots): array { arsort($snapshots); $keep = []; $i = 0; foreach ($snapshots as $id => $time) { if ($i++ < $this->last) { $keep[$id][] = 'last'; } } foreach (['daily' => 'Y-m-d', 'weekly' => 'o-W', 'monthly' => 'Y-m'] as $kind => $format) { $seen = []; foreach ($snapshots as $id => $time) { $bucket = date($format, $time); if (isset($seen[$bucket])) { continue; } if (count($seen) >= $this->$kind) { break; } $seen[$bucket] = true; $keep[$id][] = $kind; } } return $keep; } }