Fix night shift calculation & update times
This commit is contained in:
parent
4ad8385386
commit
8dda9a0dc3
|
@ -350,8 +350,8 @@ return [
|
|||
// Goodies must be enabled to use this feature
|
||||
'night_shifts' => [
|
||||
'enabled' => (bool) env('NIGHT_SHIFTS', true), // Disable to weigh every shift the same
|
||||
'start' => env('NIGHT_SHIFTS_START', 2),
|
||||
'end' => env('NIGHT_SHIFTS_END', 8),
|
||||
'start' => env('NIGHT_SHIFTS_START', 2), // Starting from hour
|
||||
'end' => env('NIGHT_SHIFTS_END', 8), // Ends at (without including) hour
|
||||
'multiplier' => env('NIGHT_SHIFTS_MULTIPLIER', 2),
|
||||
],
|
||||
|
||||
|
|
|
@ -128,8 +128,11 @@ function User_get_shifts_sum_query()
|
|||
'
|
||||
COALESCE(SUM(
|
||||
(1 + (
|
||||
HOUR(shifts.start) > %1$d AND HOUR(shifts.start) < %2$d
|
||||
OR HOUR(shifts.end) > %1$d AND HOUR(shifts.end) < %2$d
|
||||
HOUR(shifts.start) >= %1$d AND HOUR(shifts.start) < %2$d
|
||||
OR (
|
||||
HOUR(shifts.end) > %1$d
|
||||
|| HOUR(shifts.end) = %1$d AND MINUTE(shifts.end) > 0
|
||||
) AND HOUR(shifts.end) <= %2$d
|
||||
OR HOUR(shifts.start) <= %1$d AND HOUR(shifts.end) >= %2$d
|
||||
))
|
||||
* (UNIX_TIMESTAMP(shifts.end) - UNIX_TIMESTAMP(shifts.start))
|
||||
|
|
|
@ -18,8 +18,11 @@ class Shifts
|
|||
|
||||
/** @see User_get_shifts_sum_query to keep it in sync */
|
||||
return $config['enabled'] && (
|
||||
$start->hour > $config['start'] && $start->hour < $config['end']
|
||||
|| $end->hour > $config['start'] && $end->hour < $config['end']
|
||||
$start->hour >= $config['start'] && $start->hour < $config['end']
|
||||
|| (
|
||||
$end->hour > $config['start']
|
||||
|| $end->hour == $config['start'] && $end->minute > 0
|
||||
) && $end->hour <= $config['end']
|
||||
|| $start->hour <= $config['start'] && $end->hour >= $config['end']
|
||||
);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class ShiftsTest extends TestCase
|
|||
$config = new Config(['night_shifts' => [
|
||||
'enabled' => false,
|
||||
'start' => 2,
|
||||
'end' => 6,
|
||||
'end' => 8,
|
||||
'multiplier' => 2,
|
||||
]]);
|
||||
$this->app->instance('config', $config);
|
||||
|
@ -40,16 +40,24 @@ class ShiftsTest extends TestCase
|
|||
return [
|
||||
// Is night shift
|
||||
['2042-01-01 04:00', '2042-01-01 05:00', true],
|
||||
// Is night shift
|
||||
['2042-01-01 02:00', '2042-01-01 02:15', true],
|
||||
// Is night shift
|
||||
['2042-01-01 07:45', '2042-01-01 08:00', true],
|
||||
// Starts as night shift
|
||||
['2042-01-01 05:45', '2042-01-01 07:00', true],
|
||||
['2042-01-01 07:59', '2042-01-01 09:00', true],
|
||||
// Ends as night shift
|
||||
['2042-01-01 00:00', '2042-01-01 03:00', true],
|
||||
['2042-01-01 00:00', '2042-01-01 02:01', true],
|
||||
// Equals night shift
|
||||
['2042-01-01 02:00', '2042-01-01 08:00', true],
|
||||
// Contains night shift
|
||||
['2042-01-01 01:00', '2042-01-01 09:00', true],
|
||||
// Too early
|
||||
['2042-01-01 00:00', '2042-01-01 02:00', false],
|
||||
// Too late
|
||||
['2042-01-01 06:00', '2042-01-01 10:00', false],
|
||||
['2042-01-01 08:00', '2042-01-01 10:00', false],
|
||||
// Out of range
|
||||
['2042-01-01 23:00', '2042-01-02 01:00', false],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -62,7 +70,7 @@ class ShiftsTest extends TestCase
|
|||
$config = new Config(['night_shifts' => [
|
||||
'enabled' => true,
|
||||
'start' => 2,
|
||||
'end' => 6,
|
||||
'end' => 8,
|
||||
'multiplier' => 2,
|
||||
]]);
|
||||
$this->app->instance('config', $config);
|
||||
|
@ -78,7 +86,7 @@ class ShiftsTest extends TestCase
|
|||
$config = new Config(['night_shifts' => [
|
||||
'enabled' => true,
|
||||
'start' => 2,
|
||||
'end' => 6,
|
||||
'end' => 8,
|
||||
'multiplier' => 2,
|
||||
]]);
|
||||
$this->app->instance('config', $config);
|
||||
|
|
Loading…
Reference in New Issue