Skip to content

Commit

Permalink
Allow JS date format in forecast datetimes (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkissling authored Jan 3, 2024
1 parent 6d263fc commit 3ccadf4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/clock-weather-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ export class ClockWeatherCard extends LitElement {
return {
temperature: maxTemp,
templow: minTemp,
datetime: DateTime.fromISO(forecasts[0].datetime),
datetime: this.parseDateTime(forecasts[0].datetime),
condition,
precipitation_probability: precipitationProbability,
precipitation
Expand Down Expand Up @@ -690,4 +690,12 @@ export class ClockWeatherCard extends LitElement {
return 'hourly'
}
}

private parseDateTime (date: string): DateTime {
const fromIso = DateTime.fromISO(date)
if (fromIso.isValid) {
return fromIso
}
return DateTime.fromJSDate(new Date(date))
}
}

0 comments on commit 3ccadf4

Please sign in to comment.