2022-07-31 16:50:35 +02:00
|
|
|
<?php
|
|
|
|
|
2023-02-03 20:41:59 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-07-31 16:50:35 +02:00
|
|
|
namespace Engelsystem\Helpers;
|
|
|
|
|
2022-07-31 19:17:44 +02:00
|
|
|
use Carbon\Carbon;
|
2022-07-31 16:50:35 +02:00
|
|
|
|
|
|
|
// Should be moved to the shift model if it's available
|
|
|
|
class Shifts
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Check if a time range is a night shift
|
|
|
|
*/
|
|
|
|
public static function isNightShift(Carbon $start, Carbon $end): bool
|
|
|
|
{
|
|
|
|
$config = config('night_shifts');
|
|
|
|
|
|
|
|
return $config['enabled'] && (
|
|
|
|
$start->hour >= $config['start'] && $start->hour < $config['end']
|
|
|
|
|| $end->hour >= $config['start'] && $end->hour < $config['end']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate a shifts night multiplier
|
|
|
|
*/
|
|
|
|
public static function getNightShiftMultiplier(Carbon $start, Carbon $end): float
|
|
|
|
{
|
|
|
|
if (!self::isNightShift($start, $end)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return config('night_shifts')['multiplier'];
|
|
|
|
}
|
|
|
|
}
|