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" ;
12import {
23 endOfDay ,
34 endOfHour ,
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+ } ;
6690export 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} ;
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
1010 isTimeDuration ,
1111 parseRelativeTime ,
1212 parseTimeDuration ,
13+ setDateFnDefaultOptions ,
1314} from "../duration/duration" ;
1415import { parseStatistics } from "./parse-statistics" ;
1516import { 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 : { } ,
You can’t perform that action at this time.
0 commit comments