Skip to content

Commit

Permalink
Fix old safari but for relative time (#22457)
Browse files Browse the repository at this point in the history
  • Loading branch information
wendevlin authored and bramkragten committed Oct 23, 2024
1 parent 9959554 commit f4d9d55
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/components/ha-relative-time.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PropertyValues, ReactiveElement } from "lit";
import { parseISO } from "date-fns";
import { customElement, property } from "lit/decorators";
import { relativeTime } from "../common/datetime/relative_time";
import { capitalizeFirstLetter } from "../common/string/capitalize-first-letter";
Expand Down Expand Up @@ -58,7 +59,12 @@ class HaRelativeTime extends ReactiveElement {
if (!this.datetime) {
this.innerHTML = this.hass.localize("ui.components.relative_time.never");
} else {
const relTime = relativeTime(new Date(this.datetime), this.hass.locale);
const date =
typeof this.datetime === "string"
? parseISO(this.datetime)
: this.datetime;

const relTime = relativeTime(date, this.hass.locale);
this.innerHTML = this.capitalize
? capitalizeFirstLetter(relTime)
: relTime;
Expand Down

0 comments on commit f4d9d55

Please sign in to comment.