Skip to content

feat(material-luxon-adapter) add option to set zone#33579

Open
laliconfigcat wants to merge 1 commit into
angular:mainfrom
laliconfigcat:luxon-data-adapter-zone-handling
Open

feat(material-luxon-adapter) add option to set zone#33579
laliconfigcat wants to merge 1 commit into
angular:mainfrom
laliconfigcat:luxon-data-adapter-zone-handling

Conversation

@laliconfigcat

@laliconfigcat laliconfigcat commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Add zone option to be able to change the zone through MAT_LUXON_DATE_ADAPTER_OPTIONS.

In a web app where the user can set their preferred timezone apart from local and UTC, the current implementation is not sufficient. The current UTC/local works fine, but there are use cases when it is not enough.
I added a new zone option to the MatLuxonDateAdapterOptions and it is passed everywhere in the adapter.

The main issue was with the DateRangePicker. However I gave it DateTimes that were in the desired timezone, after changing the range, the new DateTime objects were in local timezone.
Also, the today highlight was wrong with the today date that was using local timezone.

Basically the change is this in the _getOptions and some minor refactorings:

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

->

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

I also added the ability to configure the zone programmatically with a public .setZone(zone: string)

The DateTimeOptions was passed to every method. I refactored it a bit so the methods that are only accepting the LocaleOptions only receive the LocaleOptions, and pass only the DateTimeOptions where the luxon methods are accepting it. This makes it clearer which methods are working with the zone and which are not. So I created a _getLocaleOptions and a _getDateTimeOptions instead of the current _getOptions. I hope you don't mind, it seems clearer to me this way.

While writing the tests, I copied the UTC tests and tried to make it work with the new zone setting. One of my tests was failing and it turned out that the original test was not working correctly. I fixed that too ("should parse dates to UTC"). The date format was wrong and the parse gave back null and the test basically tested if null equals null.

I also added some remarks to the documentation where it talked about the useUTC parameter.

@pullapprove
pullapprove Bot requested review from crisbeto and tjshiu July 23, 2026 16:37
Add zone option to be able to change the zone through MAT_LUXON_DATE_ADAPTER_OPTIONS.
@laliconfigcat
laliconfigcat force-pushed the luxon-data-adapter-zone-handling branch from d3acb55 to 905f8f2 Compare July 23, 2026 16:46
@angular-robot angular-robot Bot added the detected: feature PR contains a feature commit label Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant