Debian Codegraph @

frontend/src/lib/interval.ts

raw
1 import { _ } from "../i18n";
2
3 export type Interval = "year" | "quarter" | "month" | "week" | "day";
4
5 export const DEFAULT_INTERVAL: Interval = "month";
6
7 export const INTERVALS: Interval[] = [
8 "year",
9 "quarter",
10 "month",
11 "week",
12 "day",
13 ];
14
15 export function getInterval(s: string | null): Interval {
16 return INTERVALS.includes(s as Interval) ? (s as Interval) : DEFAULT_INTERVAL;
17 }
18
19 /** Get the translateable label for an interval. */
20 export function intervalLabel(s: Interval): string {
21 return {
22 year: _("Yearly"),
23 quarter: _("Quarterly"),
24 month: _("Monthly"),
25 week: _("Weekly"),
26 day: _("Daily"),
27 }[s];
28 }