From ae5481d881249881f7f0678323743efcc1173f89 Mon Sep 17 00:00:00 2001 From: RasmusKjeldgaard Date: Wed, 18 Dec 2024 13:05:24 +0100 Subject: [PATCH 1/2] Add failing test that verifies issue --- .../calendar/src/calendar.component.spec.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/designsystem/calendar/src/calendar.component.spec.ts b/libs/designsystem/calendar/src/calendar.component.spec.ts index 6033efeec5..5fa2d3cf1e 100644 --- a/libs/designsystem/calendar/src/calendar.component.spec.ts +++ b/libs/designsystem/calendar/src/calendar.component.spec.ts @@ -879,6 +879,16 @@ describe('CalendarComponent', () => { expect(spectator.component.selectedDate).toEqual(localMidnightDate('1997-08-14')); }); + + it('should set focussedDate to midnight of focussed date when using UTC', () => { + spectator.setInput('timezone', 'UTC'); + spectator.setInput('selectedDate', utcMidnightDate('1997-08-29')); + + const focussedDay = spectator.query('.focussed'); + spectator.dispatchKeyboardEvent(focussedDay, 'keydown', 'ArrowRight'); + + expect(spectator.component['focussedDate']).toEqual(utcMidnightDate('1997-08-30')); + }); }); // constants and utility functions From 7ab70194317f805bff68c69b1e16dbdfaed6aae2 Mon Sep 17 00:00:00 2001 From: RasmusKjeldgaard Date: Wed, 18 Dec 2024 13:09:13 +0100 Subject: [PATCH 2/2] Normalize date before setting focus --- libs/designsystem/calendar/src/calendar.component.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/designsystem/calendar/src/calendar.component.ts b/libs/designsystem/calendar/src/calendar.component.ts index 0054a1d8a6..d7d4dca6ff 100644 --- a/libs/designsystem/calendar/src/calendar.component.ts +++ b/libs/designsystem/calendar/src/calendar.component.ts @@ -547,6 +547,8 @@ export class CalendarComponent implements OnInit, OnChanges { private focusDate(newDate: Date | null) { if (!newDate) return; + newDate = this.normalizeDate(newDate); + if (this.timezone === 'UTC') { newDate = zonedTimeToUtc(this.subtractTimezoneOffset(newDate), this.timeZoneName); }