-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.ts
More file actions
37 lines (32 loc) · 990 Bytes
/
Copy pathutils.ts
File metadata and controls
37 lines (32 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { SEPARATOR } from './constants';
const defaultFormat = (hours: number, minutes: number) => {
'worklet';
return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;
};
export const minutesToTime = (
minutes: number,
format: (hours: number, minutes: number) => string = defaultFormat
) => {
'worklet';
const hours = Math.floor(minutes / 60);
const remainingMinutes = minutes % 60;
return format(hours, remainingMinutes);
};
export const calculateTotalDurations = (
indexToKey: Array<string>,
durations: Record<string, number>
) => {
const result: Record<string, number> = {};
let totalDuration = 0;
for (const key of indexToKey) {
// We want to finish when the separator is reached
// (we care only about total durations for selected tasks)
if (key === SEPARATOR) {
break;
}
const duration = durations[key] ?? 0;
totalDuration += duration;
result[key] = totalDuration;
}
return result;
};