Created
May 19, 2022 18:49
-
-
Save Gummibeer/72a5c96242b88ca66610e3b8f6503030 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Carbon\Carbon; | |
use Carbon\CarbonPeriod; | |
use Illuminate\Support\Collection; | |
$period = collect(CarbonPeriod::since(Carbon::parse('-1year'))->days(1)->until(Carbon::now())) | |
->concat(CarbonPeriod::since(Carbon::parse('-1week'))->hours(1)->until(Carbon::now())) | |
->concat(CarbonPeriod::since(Carbon::parse('-1day'))->minutes(30)->until(Carbon::now())); | |
$backupsPerPeriod = []; | |
$backupsPerPeriod['daily'] = $period->groupBy(fn (Carbon $date) => $date->format('Ymd')); | |
$backupsPerPeriod['weekly'] = $period->groupBy(fn (Carbon $date) => $date->format('YW')); | |
$backupsPerPeriod['monthly'] = $period->groupBy(fn (Carbon $date) => $date->format('Ym')); | |
$backupsPerPeriod['yearly'] = $period->groupBy(fn (Carbon $date) => $date->format('Y')); | |
collect($backupsPerPeriod) | |
->map( | |
fn(Collection $periods) => $periods | |
->map( | |
fn(Collection $backups) => $backups | |
->map->toDateTimeString() | |
->unique() | |
->sortDesc() | |
->values() | |
) | |
->sortKeysDesc() | |
) | |
->toArray(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment