-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapters.js
50 lines (43 loc) · 1.14 KB
/
adapters.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const { compose } = require("./compose");
const civilianHours = (clockTime) => ({
...clockTime,
hours: clockTime.hours > 12 ? clockTime.hours - 12 : clockTime.hours,
});
const appendAMPM = (clockTime) => ({
...clockTime,
ampm: clockTime.hours >= 12 ? "PM" : "AM",
});
const formatClock = (format) => (time) =>
format
.replace("yyyy", time.year)
.replace("oo", time.month)
.replace("dd", time.day)
.replace("hh", time.hours)
.replace("mm", time.minutes)
.replace("ss", time.seconds)
.replace("tt", time.ampm);
const prependZero = (key) => (clockTime) => {
const formated = {
...clockTime,
};
formated[key] = clockTime[key] < 10 ? "0" + clockTime[key] : clockTime[key];
return formated;
};
const convertToCivilianTime = (clockTime) =>
compose(appendAMPM, civilianHours)(clockTime);
const doubleDigits = (civilianTime) =>
compose(
prependZero("month"),
prependZero("day"),
prependZero("hours"),
prependZero("minutes"),
prependZero("seconds")
)(civilianTime);
module.exports = {
doubleDigits,
convertToCivilianTime,
prependZero,
formatClock,
appendAMPM,
civilianHours,
};