mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 11:16:35 +00:00
Display year in entities list only when last year (#23865)
* Display year in entities list only when last year * Make function * Revert hyphen
This commit is contained in:
parent
a95c589a06
commit
546087066a
@ -65,6 +65,18 @@ const formatShortDateTimeMem = memoizeOne(
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const formatShortDateTimeWithConditionalYear = (
|
||||||
|
dateObj: Date,
|
||||||
|
locale: FrontendLocaleData,
|
||||||
|
config: HassConfig
|
||||||
|
) => {
|
||||||
|
const now = new Date();
|
||||||
|
if (now.getFullYear() === dateObj.getFullYear()) {
|
||||||
|
return formatShortDateTime(dateObj, locale, config);
|
||||||
|
}
|
||||||
|
return formatShortDateTimeWithYear(dateObj, locale, config);
|
||||||
|
};
|
||||||
|
|
||||||
// August 9, 2021, 8:23:15 AM
|
// August 9, 2021, 8:23:15 AM
|
||||||
export const formatDateTimeWithSeconds = (
|
export const formatDateTimeWithSeconds = (
|
||||||
dateObj: Date,
|
dateObj: Date,
|
||||||
|
@ -23,7 +23,7 @@ import { ifDefined } from "lit/directives/if-defined";
|
|||||||
import { styleMap } from "lit/directives/style-map";
|
import { styleMap } from "lit/directives/style-map";
|
||||||
import memoize from "memoize-one";
|
import memoize from "memoize-one";
|
||||||
import { computeCssColor } from "../../../common/color/compute-color";
|
import { computeCssColor } from "../../../common/color/compute-color";
|
||||||
import { formatShortDateTimeWithYear } from "../../../common/datetime/format_date_time";
|
import { formatShortDateTimeWithConditionalYear } from "../../../common/datetime/format_date_time";
|
||||||
import { storage } from "../../../common/decorators/storage";
|
import { storage } from "../../../common/decorators/storage";
|
||||||
import type { HASSDomEvent } from "../../../common/dom/fire_event";
|
import type { HASSDomEvent } from "../../../common/dom/fire_event";
|
||||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||||
@ -410,7 +410,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
|
|||||||
minWidth: "128px",
|
minWidth: "128px",
|
||||||
template: (entry) =>
|
template: (entry) =>
|
||||||
entry.created_at
|
entry.created_at
|
||||||
? formatShortDateTimeWithYear(
|
? formatShortDateTimeWithConditionalYear(
|
||||||
new Date(entry.created_at * 1000),
|
new Date(entry.created_at * 1000),
|
||||||
this.hass.locale,
|
this.hass.locale,
|
||||||
this.hass.config
|
this.hass.config
|
||||||
@ -425,7 +425,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
|
|||||||
minWidth: "128px",
|
minWidth: "128px",
|
||||||
template: (entry) =>
|
template: (entry) =>
|
||||||
entry.modified_at
|
entry.modified_at
|
||||||
? formatShortDateTimeWithYear(
|
? formatShortDateTimeWithConditionalYear(
|
||||||
new Date(entry.modified_at * 1000),
|
new Date(entry.modified_at * 1000),
|
||||||
this.hass.locale,
|
this.hass.locale,
|
||||||
this.hass.config
|
this.hass.config
|
||||||
|
Loading…
x
Reference in New Issue
Block a user