From 31a5e6f671e5d3d830350773856b4c41ba95e976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C3=87=C4=B1rak?= Date: Tue, 5 Mar 2024 17:24:05 +0300 Subject: [PATCH 1/5] fix(npm/ng-packs/theme-shared): fix date time adapter at theme-shared --- .../src/lib/adapters/date-time.adapter.ts | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts b/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts index c461b9725b5..a19806af5f3 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts @@ -25,32 +25,15 @@ export class DateTimeAdapter { } toModel(value: Partial | null): string { - if (!value) return ''; - - const now = new Date(); - - const newValue = { - // TODO look for strict mode errors - year: now.getUTCFullYear(), - month: now.getMonth() + 1, - day: now.getDate(), - hour: 0, - minute: 0, - second: 0, - ...this.value, - ...value, - } as NgbDateTimeStruct; + if (!value) { + return ''; + } const date = new Date( - newValue.year, - newValue.month - 1, - newValue.day, - newValue.hour, - newValue.minute, - newValue.second, + Date.UTC(value.year, value.month - 1, value.day, value.hour, value.minute, value.second), ); - return new Date(date).toISOString(); + return date.toISOString(); } } From db4df4d8cfef4ed32b0ddc5ce824d50ff2b7f296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C3=87=C4=B1rak?= Date: Tue, 5 Mar 2024 17:34:23 +0300 Subject: [PATCH 2/5] fix(npm/ng-packs/theme-shared): fix date time adapter at theme-shared --- .../theme-shared/src/lib/adapters/date-time.adapter.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts b/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts index a19806af5f3..2b3acdd807a 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts @@ -30,7 +30,14 @@ export class DateTimeAdapter { } const date = new Date( - Date.UTC(value.year, value.month - 1, value.day, value.hour, value.minute, value.second), + Date.UTC( + value.year, + value.month - 1, + value.day, + value?.hour || 0, + value?.minute || 0, + value?.second || 0, + ), ); return date.toISOString(); From a602c19499743e6850ef9a35484e8f403c7fdd26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C3=87=C4=B1rak?= Date: Wed, 6 Mar 2024 09:48:35 +0300 Subject: [PATCH 3/5] format file --- .../theme-shared/src/lib/adapters/date-time.adapter.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts b/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts index 2b3acdd807a..7f6da17afde 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts @@ -6,11 +6,15 @@ export class DateTimeAdapter { value!: Partial; fromModel(value: string | Date): Partial | null { - if (!value) return null; + if (!value) { + return null; + } const date = new Date(value); - if (isNaN(date as unknown as number)) return null; + if (isNaN(date as unknown as number)) { + return null; + } this.value = { year: date.getFullYear(), From ab1a12fcd830038093f15bb721b2510e39640c8c Mon Sep 17 00:00:00 2001 From: sumeyyeKurtulus Date: Wed, 6 Mar 2024 10:23:27 +0300 Subject: [PATCH 4/5] revert changes for newValue variable --- .../src/lib/adapters/date-time.adapter.ts | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts b/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts index 7f6da17afde..bfcc095a85f 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts @@ -33,14 +33,27 @@ export class DateTimeAdapter { return ''; } + const now = new Date(); + + const newValue = { + year: now.getUTCFullYear(), + month: now.getMonth() + 1, + day: now.getDate(), + hour: 0, + minute: 0, + second: 0, + ...this.value, + ...value, + } as NgbDateTimeStruct; + const date = new Date( Date.UTC( - value.year, - value.month - 1, - value.day, - value?.hour || 0, - value?.minute || 0, - value?.second || 0, + newValue.year, + newValue.month - 1, + newValue.day, + newValue.hour, + newValue.minute, + newValue.second, ), ); From f73d484671ce23786c46d599c1f5f2676637b265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20=C3=87=C4=B1rak?= Date: Fri, 8 Mar 2024 14:57:09 +0300 Subject: [PATCH 5/5] Fix date formatting issue in DateTimeAdapter and update adapter tests --- .../src/lib/adapters/date-time.adapter.ts | 2 +- .../src/lib/tests/date-time.adapter.spec.ts | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts b/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts index bfcc095a85f..813e2c20fff 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/adapters/date-time.adapter.ts @@ -57,7 +57,7 @@ export class DateTimeAdapter { ), ); - return date.toISOString(); + return date.toISOString().replace('Z', ''); } } diff --git a/npm/ng-packs/packages/theme-shared/src/lib/tests/date-time.adapter.spec.ts b/npm/ng-packs/packages/theme-shared/src/lib/tests/date-time.adapter.spec.ts index 2c00b28fae8..d6074a90cda 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/tests/date-time.adapter.spec.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/tests/date-time.adapter.spec.ts @@ -1,4 +1,5 @@ - import { DateTimeAdapter } from '../adapters/date-time.adapter' +import { DateTimeAdapter } from '../adapters/date-time.adapter'; + describe('DateTime Adapter', () => { const adapter = new DateTimeAdapter(); const date = new Date(2002, 2, 30, 13, 30, 45, 0); @@ -9,6 +10,7 @@ describe('DateTime Adapter', () => { const minute = date.getMinutes(); const second = date.getSeconds(); + const isoWithoutZone = date.toISOString().replace('Z', ''); describe('#fromModel', () => { test.each` param | expected @@ -23,12 +25,12 @@ describe('DateTime Adapter', () => { describe('#toModel', () => { test.each` - param | expected - ${undefined} | ${''} - ${null} | ${''} - ${{ year, month, day, hour, minute, second }} | ${date.toISOString()} + param | expected + ${undefined} | ${''} + ${null} | ${''} + ${isoWithoutZone} | ${isoWithoutZone} `('should return $expected when $param is given', ({ param, expected }) => { - expect(adapter.toModel(param)).toEqual(expected); + expect(adapter.toModel(adapter.fromModel(param))).toEqual(expected); }); }); });