Skip to content

Commit

Permalink
Calendar: fix wrong date when using keyboard nav and UTC timezone (#3744
Browse files Browse the repository at this point in the history
)
  • Loading branch information
RasmusKjeldgaard authored Dec 18, 2024
1 parent f1dad44 commit 27d1f36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libs/designsystem/calendar/src/calendar.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions libs/designsystem/calendar/src/calendar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 27d1f36

Please sign in to comment.