components icon indicating copy to clipboard operation
components copied to clipboard

feat(material-luxon-adapter): Add support for Luxon 3

Open brodziakm opened this issue 2 years ago • 3 comments

Feature Description

Luxon 3.0 was released on 9 July 2022 (see changelog)

This appears to be a largely compatible release, with the exception of system zone behaviour.

Please add support for this version in the material-luxon-adapter.

Use Case

Use of Luxon 3.0 without forcing incompatible dependencies.

brodziakm avatar Aug 08 '22 00:08 brodziakm

The breaking change made in Luxon is (from the release notes)

Add "default" as an option for specifying a zone, and change "system" to really mean the system zone (breaking change)

This change does not affect the use of the material-luxon-adapter which continues to work without issue.

mcalmus avatar Aug 10 '22 10:08 mcalmus

Even if we don't need to make any code changes, I think that we'll have to expand the version range in our peerDependencies.

crisbeto avatar Aug 11 '22 09:08 crisbeto

I looked into it and it seems like this call will be broken in Luxon 3: https://github.com/angular/components/blob/main/src/material-luxon-adapter/adapter/luxon-date-adapter.ts#L200. We'll have to set the minimum required version to 3.0 which will be breaking so the change will have to wait until Angular 15.

crisbeto avatar Aug 25 '22 07:08 crisbeto

I looked into it and it seems like this call will be broken in Luxon 3: https://github.com/angular/components/blob/main/src/material-luxon-adapter/adapter/luxon-date-adapter.ts#L200. We'll have to set the minimum required version to 3.0 which will be breaking so the change will have to wait until Angular 15.

I don't think that line actually requires a change. The breaking change in Luxon only applies if "system" was set as the timezone. Because the Angular line in question uses either 'utc' or undefined, it's fine. An undefined zone when passed to toFormat() uses the default zone in both 2.5.0 and 3.0.3.

import * as luxon from "https://cdn.skypack.dev/[email protected]";

const displayFormat = 'ZZZZZ';
for (let i = 0; i < 4; i++) {
  let zone = i % 2 ? undefined : 'system';
  luxon.Settings.defaultZone = i <= 1 ? undefined : "Pacific/Guam";
  const date = luxon.DateTime.now();
  const dateStr = date
      .toFormat(displayFormat, {timeZone: zone});
  console.log(dateStr, zone, luxon.Settings.defaultZone);
}

As such, I think this can be resolved simply by setting the allowed versions of Luxon to 2 or 3.

mcalmus avatar Sep 15 '22 11:09 mcalmus

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.