Skip to content

bug(material-luxon-adapter): TimePicker with Luxon date adapter ignores the original timezone after setting a new value. #33563

Description

@laliconfigcat

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When using the timepicker with the Luxon date adapter, the DateTime's zone is ignored after setting a new value with the timepicker.
The luxon adapter is configured with useUtc: false.

The timepicker is correctly calling only the setTime on the previous valid value:

toAssign=target ? adapter.setTime(target,hours,minutes,seconds) : selection;

But the luxon data adapter is cloning the value without preserving the timezone.

returnLuxonDateTime.fromObject(date.toObject(),this._getOptions());

zone: this._useUTC ? 'utc' : undefined,

I think in this case the timezone shouldn't be set to undefined, but to the previous valid value's timezone.

I could fix the issue with a custom date adapter with overriding the clone method:

exportclassCustomLuxonDateAdapterextendsLuxonDateAdapter{overrideclone(date: DateTime): DateTime{returnDateTime.fromObject(date.toObject(),{zone: date.zone,}asDateTimeOptions);}}

Reproduction

StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-hy9xclwv?file=src%2Fmain.ts
Steps to reproduce:

  1. Use @angular/material-luxon-adapter with useUtc: false
  2. Create a luxon DateTime object with a custom timezone (not your local timezone)
  3. Set a new time on the timepicker
  4. The value's zone will be set to your local timezone.

On the stackblitz example, I printed out the zone for easier checking.

Expected Behavior

The value's timezone should be not ignored on cloning a DateTime object.

Actual Behavior

The value's timezone is set to undefined on cloning a DateTime object.

Environment

  • Angular: 22
  • CDK/Material: 22
  • Browser(s): doesn't matter, but latest Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions