Update Schedules

This commit is contained in:
R
2022-09-27 10:03:11 +07:00
parent 876e521347
commit 388f7b2a9b
9 changed files with 843 additions and 2 deletions

View File

@@ -2,6 +2,8 @@
namespace App\Helpers;
use Carbon\Carbon;
use Carbon\CarbonPeriod;
use Illuminate\Support\Collection;
class Helper{
@@ -33,4 +35,32 @@ class Helper{
'next_page_url' => $resource->nextPageUrl(),
];
}
public static function dailyAvailabilitiesToDate($dailyAvailabilities, $startDate, $endDate = null) {
Carbon::setLocale('id');
$startDate = Carbon::parse($startDate);
if ( empty($endDate) ) {
$endDate = $startDate;
} else {
$endDate = Carbon::parse($endDate);
}
$ranges = CarbonPeriod::create($startDate, $endDate);
$datesAvailabilities = [];
foreach ( $ranges as $date ) {
$datesAvailabilities[] = [
'date' => $date->format('Y-m-d'),
'day' => $date->dayName,
'slot' => $dailyAvailabilities[$date->dayName],
'timezone' => 'WIB'
];
}
return $datesAvailabilities;
}
}