From 82bee42959b84a72644826b2b2ceecafe21239c0 Mon Sep 17 00:00:00 2001 From: Zhihe Li Date: Fri, 3 Feb 2023 17:53:30 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fix=20null=20date=20time?= =?UTF-8?q?=20erroring=20out=20(#1623)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 Fix null date time erroring out * style: 💄 Remove braces in if statement --- addons/core/addon/helpers/relative-datetime-live.js | 2 ++ .../integration/helpers/relative-datetime-live-test.js | 8 ++++++++ ui/admin/app/components/form/worker/index.hbs | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/addons/core/addon/helpers/relative-datetime-live.js b/addons/core/addon/helpers/relative-datetime-live.js index 746f89643..831611cb1 100644 --- a/addons/core/addon/helpers/relative-datetime-live.js +++ b/addons/core/addon/helpers/relative-datetime-live.js @@ -45,6 +45,8 @@ export default class extends Helper { // =methods compute([date]) { + if (!date) return; + const delta = date.valueOf() - this.clockTick.now; const greatestMeaningfulUnit = unitMappings.reduce( (currentValue, previousValue) => { diff --git a/addons/core/tests/integration/helpers/relative-datetime-live-test.js b/addons/core/tests/integration/helpers/relative-datetime-live-test.js index e7e120e2c..39412a8dd 100644 --- a/addons/core/tests/integration/helpers/relative-datetime-live-test.js +++ b/addons/core/tests/integration/helpers/relative-datetime-live-test.js @@ -53,4 +53,12 @@ module('Integration | Helper | relative-datetime-live', function (hooks) { await render(hbs`{{relative-datetime-live this.date}}`); assert.dom(this.element).hasText('in 22 years'); }); + + test('it renders nothing when there is no date', async function (assert) { + assert.expect(1); + + this.date = null; + await render(hbs`{{relative-datetime-live this.date}}`); + assert.dom(this.element).hasText(''); + }); }); diff --git a/ui/admin/app/components/form/worker/index.hbs b/ui/admin/app/components/form/worker/index.hbs index 6c7115f05..009ef1326 100644 --- a/ui/admin/app/components/form/worker/index.hbs +++ b/ui/admin/app/components/form/worker/index.hbs @@ -99,7 +99,10 @@