-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeOptions.js
33 lines (27 loc) · 872 Bytes
/
timeOptions.js
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
const addTime = (hours, minutes, interval) => {
if (minutes + interval < 60) minutes += interval;
else {
hours++;
minutes -= 60;
const time = addTime(hours, minutes, interval);
hours = time.hours;
minutes = time.minutes;
}
return { hours, minutes };
};
const getTwoDigits = (num) => (num < 10 ? "0" + num : num);
const getTimeOptions = (interval) => {
const timeOptions = [];
const intervalsAmount = (60 * 24) / interval;
let hours = 0;
let minutes = 0;
for (let i = 0; i < intervalsAmount; i++) {
timeOptions.push(getTwoDigits(hours) + ":" + getTwoDigits(minutes));
const time = addTime(hours, minutes, interval);
hours = time.hours;
minutes = time.minutes;
}
return timeOptions;
};
const timeOptions = getTimeOptions(45);
console.log(timeOptions);