-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.js
More file actions
29 lines (26 loc) · 869 Bytes
/
Copy pathclock.js
File metadata and controls
29 lines (26 loc) · 869 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
const maxHours = 24;
const maxMinutes = 60;
const putZero = (number) => number < 10 ? `0${number}` : number;
const at = (hours, minutes = 0) => {
if(minutes >= maxMinutes || minutes < 0){
const overMinutes = Math.floor(minutes / maxMinutes);
const remainMinutes = minutes % maxMinutes;
hours += overMinutes;
minutes = remainMinutes;
minutes < 0 ? minutes += maxMinutes : minutes;
}
if(hours >= maxHours || hours < 0){
const remainHours = hours % maxHours;
hours = remainHours;
hours < 0 ? hours += maxHours : hours;
}
const time = `${putZero(hours)}:${putZero(minutes)}`;
return{
toString: () => time,
plus: (number) => at(hours, minutes + number),
minus: (number) => at(hours, minutes - number),
equals: (aTime) => time == aTime
//------ or ------ time === aTime.toString()
};
};
export default at;