-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
49 lines (42 loc) · 1.05 KB
/
index.ts
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
import { parser } from "./parser";
import moment from "moment";
interface Time {
hour: number,
minute: number
}
interface TimeRange {
start: Time,
end: Time
}
interface MomentRange {
start: moment.Moment,
end: moment.Moment
}
export function generateTimeRanges(
timeString : string,
forMoment : moment.Moment = moment()
): MomentRange[] {
forMoment = forMoment.startOf('day');
return parser.parse(timeString).map((range : TimeRange) => {
const start = forMoment.clone();
start.set("hour", range.start.hour);
start.set("minute", range.start.minute);
const end = forMoment.clone();
end.set("hour", range.end.hour);
end.set("minute", range.end.minute);
return {
start,
end
};
});
}
export function inspectTimeString(timeString:string) {
console.log("========================");
console.log(`timeString: \n${timeString}`);
const ranges = generateTimeRanges(timeString);
for (const range of ranges) {
console.log(`
From: ${range.start.format("LLL")}
To: ${range.end.format("LLL")}`);
}
}