From 08362ff476d983ed694699158c21f82d4a9180ae Mon Sep 17 00:00:00 2001 From: Benjamin Lyon Date: Fri, 25 Apr 2025 15:39:16 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Update=20date=20format?= =?UTF-8?q?ting=20functions=20to=20return=20undefined=20instead=20of=20emp?= =?UTF-8?q?ty=20string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/atoms/utils/date.test.ts | 18 ++++++++++++++---- src/atoms/utils/date.ts | 12 ++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/atoms/utils/date.test.ts b/src/atoms/utils/date.test.ts index cd75d7d00..16c603240 100644 --- a/src/atoms/utils/date.test.ts +++ b/src/atoms/utils/date.test.ts @@ -10,7 +10,7 @@ import { test('formatDate works as expected when not sending in a date', () => { const formattedDate = formatDate(null); - expect(formattedDate).toBe(''); + expect(formattedDate).toBe(undefined); }); test('formatDate works as expected with default format', () => { @@ -177,6 +177,11 @@ test('formatDate works as expected with format = "DD. month" and month = "short" expect(formattedDate).toBe(testFormatted); }); +test('formatDate with null should be undefined', () => { + const formatted = formatDate(null); + expect(formatted).toBe(undefined); +}); + test('formatDateTime works as expected', () => { const today = new Date(); const fakeDate = faker.date.past({ @@ -196,7 +201,7 @@ test('formatDateTime works as expected', () => { test('formatDateTime works as expected when not sending in a date', () => { const formatted = formatDateTime(null); - expect(formatted).toBe(''); + expect(formatted).toBe(undefined); }); test('formatDateTime works as expected with options', () => { @@ -234,9 +239,9 @@ test('formatDateTime works as expected when isGMT is set', () => { expect(formatted).toBe(expectedResult); }); -test('formatRelativeDateTime with null should be empty string', () => { +test('formatRelativeDateTime with null should be undefined', () => { const formatted = formatRelativeDateTime(null); - expect(formatted).toContain(''); + expect(formatted).toBe(undefined); }); test('formatRelativeDateTime with isGMT set should convert to local time', () => { @@ -421,6 +426,11 @@ test('formatRelativeDateTime with date not in current year displays as full date expect(formattedDateInNextYear).toBe(expectedNextYearResult); }); +test('formatRelativeDateTime with null should be undefined ', () => { + const formatted = formatDate(null); + expect(formatted).toBe(undefined); +}); + test('isBetweenDates works as expected with null', () => { const yesterday = new Date(new Date().setDate(new Date().getDate() - 1)); const tomorrow = new Date(new Date().setDate(new Date().getDate() + 1)); diff --git a/src/atoms/utils/date.ts b/src/atoms/utils/date.ts index 2e2028b32..0ece1e5c6 100644 --- a/src/atoms/utils/date.ts +++ b/src/atoms/utils/date.ts @@ -20,7 +20,7 @@ export const formatDate = ( format: 'DD. month YYYY', month: 'long', } -): string => { +): string | undefined => { if (date) { const dateObj = new Date(date); if (dateObj.getTime()) { @@ -68,7 +68,7 @@ export const formatDate = ( .padStart(2, '0')}.${year.toString().padStart(4, '0')}`; } } - return ''; + return undefined; }; // formatDateTime(new Date()) => 19. January 2022, 01:32 @@ -80,7 +80,7 @@ export const formatDateTime = ( hideYear: false, isGMT: false, } -): string => { +): string | undefined => { if (date) { const dateObj = new Date(date); if (dateObj.getTime()) { @@ -98,7 +98,7 @@ export const formatDateTime = ( })}`; } } - return ''; + return undefined; }; // formatRelativeDateTime(new Date()) => Today at 7:17 @@ -106,7 +106,7 @@ export const formatDateTime = ( export const formatRelativeDateTime = ( date: Date | string | null | undefined, isGMT = false -): string => { +): string | undefined => { if (date) { const dateObj = new Date(date); const today = new Date(); @@ -150,7 +150,7 @@ export const formatRelativeDateTime = ( } } } - return ''; + return undefined; }; export const isBetweenDates = ( From 2af92803489bb29293d7cbecc97bfdefee17afe9 Mon Sep 17 00:00:00 2001 From: Benjamin Lyon Date: Fri, 25 Apr 2025 15:41:38 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=96=209.9.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 115f5921b..74185c588 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@equinor/amplify-component-lib", - "version": "9.9.1", + "version": "9.9.2", "description": "Frontend Typescript components for the Amplify team", "main": "dist/index.js", "types": "dist/index.d.ts",