Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar: fix wrong date when using keyboard nav and UTC timezone #3744

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading