Skip to content

Instantly share code, notes, and snippets.

@dwihujianto
Created January 27, 2020 07:42
Show Gist options
  • Save dwihujianto/af07fd3cb0e01f73ad6557b9c3952f05 to your computer and use it in GitHub Desktop.
Save dwihujianto/af07fd3cb0e01f73ad6557b9c3952f05 to your computer and use it in GitHub Desktop.
<?php
public function workDay()
{
$aDates = [];
$aDateRanges = \Carbon\CarbonPeriod::create('2020-01-01', '2020-01-23');
foreach ($aDateRanges->toArray() as $date) {
$aDates[] = $date->format('Y-m-d');
}
$total = collect($aDates)->filter(function($date) {
return ! in_array(\Carbon\Carbon::parse($date)->format('l'), ['Saturday','Sunday']);
})->groupBy(function($date) {
return \Carbon\Carbon::parse($date)->format('W');
})->map(function($date) {
return count($date);
})->reduce(function($carry, $item) {
return $carry + ($item * 8);
});
dd($total);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment