Skip to content
This repository was archived by the owner on Mar 10, 2023. It is now read-only.

Commit 60dabd8

Browse files
authored
Merge pull request #29 from AitorDB/bugfix/fix-fi-time-format
Fix for Finnish time format and fallback
2 parents c90054b + 800e69d commit 60dabd8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,17 @@ class SunCard extends LitElement {
8383
return (date.getHours() * 60) + date.getMinutes()
8484
}
8585

86-
parseTime (timeText: string) {
87-
const regex = /\d{1,2}:\d{1,2}|[AMP]+/g
86+
parseTime (timeText: string, locale?: string) {
87+
const regex = /\d{1,2}[:.]\d{1,2}|[AMP]+/g
8888
const date = new Date(timeText)
8989
const { language, timeFormat } = this.getConfig()
90-
const [time, period] = date.toLocaleTimeString(language, { hour12: timeFormat === '12h' }).match(regex) as [string, ('AM' | 'PM')?]
90+
const result = date.toLocaleTimeString(locale ?? language, { hour12: timeFormat === '12h' }).match(regex) as [string, ('AM' | 'PM')?]
91+
92+
if (!result && !locale) {
93+
return this.parseTime(timeText, Constants.DEFAULT_CONFIG.language)
94+
}
95+
96+
const [time, period] = result
9197
return { time, period }
9298
}
9399

0 commit comments

Comments
 (0)