From d6e9db0084f50ff2a02a7a949597cb441c3aad58 Mon Sep 17 00:00:00 2001 From: Lajos Szoke Date: Wed, 22 Jul 2026 07:24:47 +0200 Subject: [PATCH] fix(angular/material-luxon-adapter): preserve timezone on .clone() Fixes a bug in the Angular Material LuxonDateAdapter where the .clone() method didn't clone the zone of the original DateTime object and caused issues with the TimePicker component. Fixes #33563 --- .../adapter/luxon-date-adapter.spec.ts | 16 ++++++++++++++++ .../adapter/luxon-date-adapter.ts | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts b/src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts index 962ea66ee11f..a8873f36afd2 100644 --- a/src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts +++ b/src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts @@ -418,6 +418,22 @@ describe('LuxonDateAdapter', () => { expect(clone.toISO()).toEqual(date.toISO()); }); + it('should respect timezone on clone', () => { + const dateLocal = DateTime.local(2017, JAN, 1); + const dateInCet = dateLocal.setZone('Europe/Budapest'); + const cloneInCet = adapter.clone(dateInCet); + const dateInPst = dateLocal.setZone('America/Los_Angeles'); + const cloneInPst = adapter.clone(dateInPst); + + expect(cloneInCet).not.toBe(dateInCet); + expect(cloneInCet.toISO()).toEqual(dateInCet.toISO()); + expect(cloneInCet.zone).toEqual(dateInCet.zone); + + expect(cloneInPst).not.toBe(dateInPst); + expect(cloneInPst.toISO()).toEqual(dateInPst.toISO()); + expect(cloneInPst.zone).toEqual(dateInPst.zone); + }); + it('should compare dates', () => { expect( adapter.compareDate(DateTime.local(2017, JAN, 1), DateTime.local(2017, JAN, 2)), diff --git a/src/material-luxon-adapter/adapter/luxon-date-adapter.ts b/src/material-luxon-adapter/adapter/luxon-date-adapter.ts index e59827031f79..4afd606ac727 100644 --- a/src/material-luxon-adapter/adapter/luxon-date-adapter.ts +++ b/src/material-luxon-adapter/adapter/luxon-date-adapter.ts @@ -134,7 +134,10 @@ export class LuxonDateAdapter extends DateAdapter { } clone(date: LuxonDateTime): LuxonDateTime { - return LuxonDateTime.fromObject(date.toObject(), this._getOptions()); + return LuxonDateTime.fromObject(date.toObject(), { + ...this._getOptions(), + zone: date.zone, + }); } createDate(year: number, month: number, date: number): LuxonDateTime {