From d2e2a92d0d62168c7ddb107d456ad8938edcd8a8 Mon Sep 17 00:00:00 2001 From: Birte Jelsa Date: Wed, 13 Sep 2023 07:40:19 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Ensure=202-digit=20day=20and?= =?UTF-8?q?=20month?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/date.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/utils/date.ts b/src/utils/date.ts index affe2e6fd..f3f745b4e 100644 --- a/src/utils/date.ts +++ b/src/utils/date.ts @@ -34,16 +34,12 @@ const formatDate = ( })}`; } if (options?.format === 'YYYY-MM-DD') { - return `${year}-${month}-${day}`; + return `${year}-${month.toString().padStart(2,'0')}-${day.toString().padStart(2,'0')}`; } if (options?.format === 'DD.MM.YY') { - return `${day < 10 ? '0' + day : day}.${ - month < 10 ? '0' + month : month - }.${year.toString().slice(-2)}`; + return `${day.toString().padStart(2,'0')}.${month.toString().padStart(2,'0')}.${year.toString().slice(-2)}`; } - return `${day < 10 ? '0' + day : day}.${ - month < 10 ? '0' + month : month - }.${year}`; + return `${day.toString().padStart(2,'0')}.${month.toString().padStart(2,'0')}.${year}`; } } return ''; From adc79c1b0be33046c445a207839a1601ac3c678d Mon Sep 17 00:00:00 2001 From: Birte Jelsa Date: Wed, 13 Sep 2023 08:20:40 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=85=20Update=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/date.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/date.test.ts b/src/utils/date.test.ts index 2a229e687..76b6106c5 100644 --- a/src/utils/date.test.ts +++ b/src/utils/date.test.ts @@ -73,7 +73,7 @@ test('formatDate works as expected with format = "YYYY-MM-DD"', () => { const day = fakeDate.getDate(); const month = fakeDate.getMonth() + 1; const year = fakeDate.getFullYear(); - expect(formattedDate).toBe(`${year}-${month}-${day}`); + expect(formattedDate).toBe(`${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`); }); test('formatDate works as expected with format = "DD.MM.YY"', () => {