forked from observablehq/plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime.js
50 lines (46 loc) · 1.5 KB
/
time.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
import {utcSecond, utcMinute, utcHour, utcDay, utcWeek, utcMonth, utcYear} from "d3";
import {utcMonday, utcTuesday, utcWednesday, utcThursday, utcFriday, utcSaturday, utcSunday} from "d3";
import {timeSecond, timeMinute, timeHour, timeDay, timeWeek, timeMonth, timeYear} from "d3";
import {timeMonday, timeTuesday, timeWednesday, timeThursday, timeFriday, timeSaturday, timeSunday} from "d3";
const timeIntervals = new Map([
["second", timeSecond],
["minute", timeMinute],
["hour", timeHour],
["day", timeDay],
["week", timeWeek],
["month", timeMonth],
["year", timeYear],
["monday", timeMonday],
["tuesday", timeTuesday],
["wednesday", timeWednesday],
["thursday", timeThursday],
["friday", timeFriday],
["saturday", timeSaturday],
["sunday", timeSunday]
]);
const utcIntervals = new Map([
["second", utcSecond],
["minute", utcMinute],
["hour", utcHour],
["day", utcDay],
["week", utcWeek],
["month", utcMonth],
["year", utcYear],
["monday", utcMonday],
["tuesday", utcTuesday],
["wednesday", utcWednesday],
["thursday", utcThursday],
["friday", utcFriday],
["saturday", utcSaturday],
["sunday", utcSunday]
]);
export function maybeTimeInterval(interval) {
const i = timeIntervals.get(`${interval}`.toLowerCase());
if (!i) throw new Error(`unknown interval: ${interval}`);
return i;
}
export function maybeUtcInterval(interval) {
const i = utcIntervals.get(`${interval}`.toLowerCase());
if (!i) throw new Error(`unknown interval: ${interval}`);
return i;
}