From 863eb71b5e9d15803a6d4ac218b0d44ecaa7224e Mon Sep 17 00:00:00 2001 From: Max Chodorowski Date: Thu, 21 Dec 2023 21:20:40 +0000 Subject: [PATCH] Stopped unnecessary date processing --- src/custom-elements/battery-state-entity.views.ts | 4 ++-- src/rich-string-processor.ts | 2 +- test/other/rich-string-processor.test.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/custom-elements/battery-state-entity.views.ts b/src/custom-elements/battery-state-entity.views.ts index d7456ea..951fa1a 100644 --- a/src/custom-elements/battery-state-entity.views.ts +++ b/src/custom-elements/battery-state-entity.views.ts @@ -2,7 +2,7 @@ import { HomeAssistant } from "custom-card-helpers"; import { TemplateResult, html } from "lit"; import { BatteryStateEntity } from "./battery-state-entity"; -const relativeTimeTag = new RegExp("([0-9]+)", "g"); +const relativeTimeTag = new RegExp("([^<]+)", "g"); /** * Replaces temporary RT tages with proper HA "relative-time" ones @@ -24,7 +24,7 @@ const replaceTags = (text: string, hass?: HomeAssistant): TemplateResult[] => { result.push(html`${text.substring(currentPos, matchPos)}`); } - result.push(html``); + result.push(html``); currentPos += matchPos + matches[0].length; } diff --git a/src/rich-string-processor.ts b/src/rich-string-processor.ts index e65acc1..cfac250 100644 --- a/src/rich-string-processor.ts +++ b/src/rich-string-processor.ts @@ -200,7 +200,7 @@ const availableProcessors: IMap = { } // The RT tags will be converted to proper HA tags at the views layer - return `${unixTime}` + return `${val}` }; } } diff --git a/test/other/rich-string-processor.test.ts b/test/other/rich-string-processor.test.ts index 3dc9ed8..bb40066 100644 --- a/test/other/rich-string-processor.test.ts +++ b/test/other/rich-string-processor.test.ts @@ -169,8 +169,8 @@ describe("RichStringProcessor", () => { }); test.each([ - ["{state|reltime()}", new Date(2021, 7, 25).toUTCString(), "1629846000000"], - ["Rel time: {state|reltime()}", new Date(2021, 7, 25).toUTCString(), "Rel time: 1629846000000"], + ["{state|reltime()}", "2021-08-25T00:00:00.000Z", "2021-08-25T00:00:00.000Z"], + ["Rel time: {state|reltime()}", "2021-08-25T00:00:00.000Z", "Rel time: 2021-08-25T00:00:00.000Z"], ["Not date: {state|reltime()}", "this is not date", "Not date: this is not date"], ])("reltime function", (text: string, state:string, expectedResult: string) => { const hassMock = new HomeAssistantMock(true);