mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 01:36:49 +00:00
Update automation picker to use differenceInDays from date-fns (#13980)
This commit is contained in:
parent
c38892a162
commit
0ac2393ecb
@ -14,6 +14,7 @@ import "@polymer/paper-tooltip/paper-tooltip";
|
||||
import { CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { differenceInDays } from "date-fns/esm";
|
||||
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
||||
import { formatShortDateTime } from "../../../common/datetime/format_date_time";
|
||||
import { relativeTime } from "../../../common/datetime/relative_time";
|
||||
@ -50,8 +51,6 @@ import { documentationUrl } from "../../../util/documentation-url";
|
||||
import { configSections } from "../ha-panel-config";
|
||||
import { showNewAutomationDialog } from "./show-dialog-new-automation";
|
||||
|
||||
const DAY_IN_MILLISECONDS = 86400000;
|
||||
|
||||
@customElement("ha-automation-picker")
|
||||
class HaAutomationPicker extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
@ -109,16 +108,13 @@ class HaAutomationPicker extends LitElement {
|
||||
? (name, automation: any) => {
|
||||
const date = new Date(automation.attributes.last_triggered);
|
||||
const now = new Date();
|
||||
|
||||
const diff = now.getTime() - date.getTime();
|
||||
const dayDiff = diff / DAY_IN_MILLISECONDS;
|
||||
|
||||
const dayDifference = differenceInDays(now, date);
|
||||
return html`
|
||||
${name}
|
||||
<div class="secondary">
|
||||
${this.hass.localize("ui.card.automation.last_triggered")}:
|
||||
${automation.attributes.last_triggered
|
||||
? dayDiff > 3
|
||||
? dayDifference > 3
|
||||
? formatShortDateTime(date, this.hass.locale)
|
||||
: relativeTime(date, this.hass.locale)
|
||||
: this.hass.localize("ui.components.relative_time.never")}
|
||||
@ -136,13 +132,10 @@ class HaAutomationPicker extends LitElement {
|
||||
template: (last_triggered) => {
|
||||
const date = new Date(last_triggered);
|
||||
const now = new Date();
|
||||
|
||||
const diff = now.getTime() - date.getTime();
|
||||
const dayDiff = diff / DAY_IN_MILLISECONDS;
|
||||
|
||||
const dayDifference = differenceInDays(now, date);
|
||||
return html`
|
||||
${last_triggered
|
||||
? dayDiff > 3
|
||||
? dayDifference > 3
|
||||
? formatShortDateTime(date, this.hass.locale)
|
||||
: relativeTime(date, this.hass.locale)
|
||||
: this.hass.localize("ui.components.relative_time.never")}
|
||||
|
Loading…
x
Reference in New Issue
Block a user