Skip to content

Commit fa6c8bd

Browse files
committed
respect user set locale in hours_to_show: current_week
1 parent 1af531f commit fa6c8bd

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/duration/duration.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { HomeAssistant } from "custom-card-helpers";
12
import {
23
endOfDay,
34
endOfHour,
@@ -6,6 +7,7 @@ import {
67
endOfQuarter,
78
endOfWeek,
89
endOfYear,
10+
setDefaultOptions,
911
startOfDay,
1012
startOfHour,
1113
startOfMinute,
@@ -63,6 +65,28 @@ export const isTimeDuration = (str: any) => {
6365
}
6466
};
6567

68+
export const setDateFnDefaultOptions = (hass: HomeAssistant) => {
69+
const first_weekday: "sunday" | "saturday" | "monday" | "language" = (
70+
hass.locale as any
71+
).first_weekday;
72+
const weekStartsOn = (
73+
{
74+
language: undefined,
75+
sunday: 0,
76+
monday: 1,
77+
tuesday: 2,
78+
wednesday: 3,
79+
thursday: 4,
80+
friday: 5,
81+
saturday: 6,
82+
} as const
83+
)[first_weekday];
84+
85+
setDefaultOptions({
86+
locale: { code: hass.locale.language },
87+
weekStartsOn,
88+
});
89+
};
6690
export const parseRelativeTime = (str: string): [number, number] => {
6791
const now = new Date();
6892
switch (str) {
@@ -89,6 +113,7 @@ export const isRelativeTime = (str: any) => {
89113
parseRelativeTime(str);
90114
return true;
91115
} catch (e) {
116+
console.log(e);
92117
return false;
93118
}
94119
};

src/parse-config/parse-config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
isTimeDuration,
1111
parseRelativeTime,
1212
parseTimeDuration,
13+
setDateFnDefaultOptions,
1314
} from "../duration/duration";
1415
import { parseStatistics } from "./parse-statistics";
1516
import { HomeAssistant } from "custom-card-helpers";
@@ -59,6 +60,7 @@ class ConfigParser {
5960
this.errors = [];
6061
this.hass = hass;
6162
this.yaml_with_defaults = addPreParsingDefaults(input_yaml, css_vars);
63+
setDateFnDefaultOptions(hass);
6264

6365
this.fnParam = {
6466
vars: {},

0 commit comments

Comments
 (0)