Skip to content

Commit

Permalink
Better usage of Carbon
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti committed May 1, 2020
1 parent 2e70c52 commit a1ec0bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule)
{
$isLatestWorkingDay = function () {
$today = now()->timezone(config('app.report_timezone'));
$today = now(config('app.report_timezone'));
$lastWorkingDay = App\Report::lastWorkingDayOfWeek();

return $today->isSameDay($lastWorkingDay);
Expand Down
22 changes: 5 additions & 17 deletions app/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,10 @@ public function getMonthAttribute()

public static function canBeFilled()
{
$now = now()->timezone(config('app.report_timezone'));
$dayOfWeek = $now->shortEnglishDayOfWeek;
$now = now(config('app.report_timezone'));
$target = Carbon::parse('Friday this week 15:05', config('app.report_timezone'));

if (in_array($dayOfWeek, ['Mon', 'Tue', 'Wed', 'Thu'])) {
return true;
}

if ($dayOfWeek === 'Fri' and $now->hour <= 14) {
return true;
}

if ($dayOfWeek === 'Fri' and $now->hour == 15 and $now->minute < 5) {
return true;
}

return false;
return $now < $target;
}

public static function latestPublishedWeek()
Expand All @@ -61,8 +49,8 @@ public static function latestPublishedWeek()

public static function lastWorkingDayOfWeek()
{
$now = now()->timezone(config('app.report_timezone'));
$candidate = $now->startOfWeek()->next(Carbon::FRIDAY);
$now = now(config('app.report_timezone'));
$candidate = Carbon::parse('Friday this week', config('app.report_timezone'));

try {
$country = Yasumi::getProviders()[config('app.report_country_code')];
Expand Down

0 comments on commit a1ec0bf

Please sign in to comment.