File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { HomeAssistant } from "custom-card-helpers" ;
1
2
import {
2
3
endOfDay ,
3
4
endOfHour ,
6
7
endOfQuarter ,
7
8
endOfWeek ,
8
9
endOfYear ,
10
+ setDefaultOptions ,
9
11
startOfDay ,
10
12
startOfHour ,
11
13
startOfMinute ,
@@ -63,6 +65,28 @@ export const isTimeDuration = (str: any) => {
63
65
}
64
66
} ;
65
67
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
+ } ;
66
90
export const parseRelativeTime = ( str : string ) : [ number , number ] => {
67
91
const now = new Date ( ) ;
68
92
switch ( str ) {
@@ -89,6 +113,7 @@ export const isRelativeTime = (str: any) => {
89
113
parseRelativeTime ( str ) ;
90
114
return true ;
91
115
} catch ( e ) {
116
+ console . log ( e ) ;
92
117
return false ;
93
118
}
94
119
} ;
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
10
10
isTimeDuration ,
11
11
parseRelativeTime ,
12
12
parseTimeDuration ,
13
+ setDateFnDefaultOptions ,
13
14
} from "../duration/duration" ;
14
15
import { parseStatistics } from "./parse-statistics" ;
15
16
import { HomeAssistant } from "custom-card-helpers" ;
@@ -59,6 +60,7 @@ class ConfigParser {
59
60
this . errors = [ ] ;
60
61
this . hass = hass ;
61
62
this . yaml_with_defaults = addPreParsingDefaults ( input_yaml , css_vars ) ;
63
+ setDateFnDefaultOptions ( hass ) ;
62
64
63
65
this . fnParam = {
64
66
vars : { } ,
You can’t perform that action at this time.
0 commit comments