-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathunits.ts
More file actions
41 lines (31 loc) · 884 Bytes
/
units.ts
File metadata and controls
41 lines (31 loc) · 884 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
30
31
32
33
34
35
36
37
38
39
40
41
import settings from "./settings";
import type { DateFormat } from "./settings";
import { LENGTH_UNIT } from "./types/evcc";
const MILES_FACTOR = 0.6213711922;
function isMiles() {
return settings.unit === LENGTH_UNIT.MILES;
}
export function distanceValue(value: number) {
return isMiles() ? value * MILES_FACTOR : value;
}
export function distanceUnit() {
return isMiles() ? "mi" : "km";
}
export function getUnits() {
return isMiles() ? LENGTH_UNIT.MILES : LENGTH_UNIT.KM;
}
export function setUnits(value: LENGTH_UNIT) {
settings.unit = value;
}
export function is12hFormat() {
return settings.is12hFormat;
}
export function set12hFormat(value: boolean) {
settings.is12hFormat = value;
}
export function getDateFormat(): DateFormat {
return settings.dateFormat || "";
}
export function setDateFormat(value: DateFormat) {
settings.dateFormat = value;
}