diff options
Diffstat (limited to 'src/helpers')
-rw-r--r-- | src/helpers/array-helpers.ts | 9 | ||||
-rw-r--r-- | src/helpers/async-helpers.ts | 4 | ||||
-rw-r--r-- | src/helpers/routing-helpers.ts | 3 | ||||
-rw-r--r-- | src/helpers/schedule-helpers.ts | 53 | ||||
-rw-r--r-- | src/helpers/url-helpers.ts | 5 |
5 files changed, 27 insertions, 47 deletions
diff --git a/src/helpers/array-helpers.ts b/src/helpers/array-helpers.ts index ae5d8d99f..3f8806176 100644 --- a/src/helpers/array-helpers.ts +++ b/src/helpers/array-helpers.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | export const shuffleArray = (arr: any[]) => arr | 1 | export const shuffleArray = (arr: any[]) => |
2 | .map((a) => [Math.random(), a]) | 2 | arr |
3 | .sort((a, b) => a[0] - b[0]) | 3 | .map(a => [Math.random(), a]) |
4 | .map((a) => a[1]); | 4 | .sort((a, b) => a[0] - b[0]) |
5 | .map(a => a[1]); | ||
diff --git a/src/helpers/async-helpers.ts b/src/helpers/async-helpers.ts index aae3c3928..6b1f24b5a 100644 --- a/src/helpers/async-helpers.ts +++ b/src/helpers/async-helpers.ts | |||
@@ -1,5 +1,3 @@ | |||
1 | /* eslint-disable import/prefer-default-export */ | ||
2 | |||
3 | export function sleep(ms: number = 0) { | 1 | export function sleep(ms: number = 0) { |
4 | return new Promise((r) => setTimeout(r, ms)); | 2 | return new Promise(r => setTimeout(r, ms)); |
5 | } | 3 | } |
diff --git a/src/helpers/routing-helpers.ts b/src/helpers/routing-helpers.ts index 18169f01b..46895aa6b 100644 --- a/src/helpers/routing-helpers.ts +++ b/src/helpers/routing-helpers.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import RouteParser from 'route-parser'; | 1 | import RouteParser from 'route-parser'; |
2 | 2 | ||
3 | export const matchRoute = (pattern: string, path: string) => new RouteParser(pattern).match(path); | 3 | export const matchRoute = (pattern: string, path: string) => |
4 | new RouteParser(pattern).match(path); | ||
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; |
diff --git a/src/helpers/url-helpers.ts b/src/helpers/url-helpers.ts index 1e87ecabb..135f06cbf 100644 --- a/src/helpers/url-helpers.ts +++ b/src/helpers/url-helpers.ts | |||
@@ -29,7 +29,10 @@ export async function openPath(folderName: string) { | |||
29 | } | 29 | } |
30 | 30 | ||
31 | // TODO: Need to verify and fix/remove the skipping logic. Ideally, we should never skip this check | 31 | // TODO: Need to verify and fix/remove the skipping logic. Ideally, we should never skip this check |
32 | export function openExternalUrl(url: string | URL, skipValidityCheck: boolean = false) { | 32 | export function openExternalUrl( |
33 | url: string | URL, | ||
34 | skipValidityCheck: boolean = false, | ||
35 | ) { | ||
33 | debug('Open url:', url, 'with skipValidityCheck:', skipValidityCheck); | 36 | debug('Open url:', url, 'with skipValidityCheck:', skipValidityCheck); |
34 | if (skipValidityCheck || isValidExternalURL(url)) { | 37 | if (skipValidityCheck || isValidExternalURL(url)) { |
35 | shell.openExternal(url.toString()); | 38 | shell.openExternal(url.toString()); |