diff options
author | 2021-10-15 09:48:06 +0200 | |
---|---|---|
committer | 2021-10-15 09:48:06 +0200 | |
commit | 14d2364fc69e0222133115c55a36286986006098 (patch) | |
tree | 9e9b3c41ef742bbe87ca1632b292c67043051957 /src/helpers/schedule-helpers.ts | |
parent | 5.6.3-nightly.34 [skip ci] (diff) | |
download | ferdium-app-14d2364fc69e0222133115c55a36286986006098.tar.gz ferdium-app-14d2364fc69e0222133115c55a36286986006098.tar.zst ferdium-app-14d2364fc69e0222133115c55a36286986006098.zip |
chore: update eslint setup (#2074)
Diffstat (limited to 'src/helpers/schedule-helpers.ts')
-rw-r--r-- | src/helpers/schedule-helpers.ts | 53 |
1 files changed, 15 insertions, 38 deletions
diff --git a/src/helpers/schedule-helpers.ts b/src/helpers/schedule-helpers.ts index 55b7c1e6f..37caffd79 100644 --- a/src/helpers/schedule-helpers.ts +++ b/src/helpers/schedule-helpers.ts | |||
@@ -1,17 +1,9 @@ | |||
1 | /* eslint-disable import/prefer-default-export */ | ||
2 | |||
3 | export function isInTimeframe(start: string, end: string) { | 1 | export function isInTimeframe(start: string, end: string) { |
4 | const [ | 2 | const [startHourStr, startMinuteStr] = start.split(':'); |
5 | startHourStr, | ||
6 | startMinuteStr, | ||
7 | ] = start.split(':'); | ||
8 | const startHour = Number.parseInt(startHourStr, 10); | 3 | const startHour = Number.parseInt(startHourStr, 10); |
9 | const startMinute = Number.parseInt(startMinuteStr, 10); | 4 | const startMinute = Number.parseInt(startMinuteStr, 10); |
10 | 5 | ||
11 | const [ | 6 | const [endHourStr, endMinuteStr] = end.split(':'); |
12 | endHourStr, | ||
13 | endMinuteStr, | ||
14 | ] = end.split(':'); | ||
15 | const endHour = Number.parseInt(endHourStr, 10); | 7 | const endHour = Number.parseInt(endHourStr, 10); |
16 | const endMinute = Number.parseInt(endMinuteStr, 10); | 8 | const endMinute = Number.parseInt(endMinuteStr, 10); |
17 | 9 | ||
@@ -20,46 +12,31 @@ export function isInTimeframe(start: string, end: string) { | |||
20 | 12 | ||
21 | // Check if the end time is before the start time (scheduled overnight) | 13 | // Check if the end time is before the start time (scheduled overnight) |
22 | // as we need to change our checks based on this | 14 | // as we need to change our checks based on this |
23 | const endBeforeStart = (startHour > endHour || (startHour === endHour && startMinute > endMinute)); | 15 | const endBeforeStart = |
16 | startHour > endHour || (startHour === endHour && startMinute > endMinute); | ||
24 | 17 | ||
25 | if ( | 18 | if ( |
26 | // End is after start (e.g. 09:00-17:00) | 19 | // End is after start (e.g. 09:00-17:00) |
27 | !endBeforeStart | 20 | !endBeforeStart && |
28 | // Check if past start | 21 | // Check if past start |
29 | && ((currentHour > startHour | 22 | (currentHour > startHour || |
30 | || ( | 23 | (currentHour === startHour && currentMinute >= startMinute)) && |
31 | currentHour === startHour | 24 | // Check that not past end |
32 | && currentMinute >= startMinute | 25 | (currentHour < endHour || |
33 | ) | 26 | (currentHour === endHour && currentMinute < endMinute)) |
34 | ) | ||
35 | // Check that not past end | ||
36 | && (currentHour < endHour | ||
37 | || ( | ||
38 | currentHour === endHour | ||
39 | && currentMinute < endMinute | ||
40 | ) | ||
41 | )) | ||
42 | ) { | 27 | ) { |
43 | // We are in scheduled timeframe | 28 | // We are in scheduled timeframe |
44 | return true; | 29 | return true; |
45 | } | 30 | } |
46 | if ( | 31 | if ( |
47 | // End is before start (e.g. 17:00-09:00) | 32 | // End is before start (e.g. 17:00-09:00) |
48 | endBeforeStart | 33 | endBeforeStart && |
49 | // Check if past start | 34 | // Check if past start |
50 | && ((currentHour > startHour | 35 | (currentHour > startHour || |
51 | || ( | 36 | (currentHour === startHour && currentMinute >= startMinute) || |
52 | currentHour === startHour | ||
53 | && currentMinute >= startMinute | ||
54 | ) | ||
55 | ) | ||
56 | // Check that we are not past end | 37 | // Check that we are not past end |
57 | || (currentHour < endHour | 38 | currentHour < endHour || |
58 | || ( | 39 | (currentHour === endHour && currentMinute < endMinute)) |
59 | currentHour === endHour | ||
60 | && currentMinute < endMinute | ||
61 | ) | ||
62 | )) | ||
63 | ) { | 40 | ) { |
64 | // We are also in scheduled timeframe | 41 | // We are also in scheduled timeframe |
65 | return true; | 42 | return true; |