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

Custom zone formatting support #1377

Merged
merged 3 commits into from Mar 4, 2023
Merged

Conversation

thatsmydoing
Copy link
Contributor

This addresses #1363

This addresses a couple of bugs related to non-IANA timezone formatting

  • timezones can be displayed even if timeZoneName is not set and partial hour fixed-offset zones don't handle this properly
  • non-universal custom non-IANA zones are treated as IANA zones and are improperly formatted
  • allow all zones to have timezone in the format using formatToParts

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 9, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

z = "UTC";
if (opts.timeZoneName) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't entirely correct since using timeStyle: "full" will also show the timezone.

if (opts.timeZoneName) {
this.dt = dt;
} else {
this.dt = dt.offset === 0 ? dt : DateTime.fromMillis(dt.ts + dt.offset * 60 * 1000);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This throws away any locale information so it would be more correct to just switch the datetime to UTC and apply the offset there.

if (part.type === "timeZoneName") {
const offsetName = this.originalZone.offsetName(this.dt.ts, {
locale: this.dt.locale,
format: this.opts.timeZoneName,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs currently say the format allows short or long but Intl.DateTimeFormat now supports more options. I think it's more correct to just pass it through as the IANAZone technically allows you to pass any of the valid options. To be more correct, we might also want to consider adding timeStyle as an option since that can also influence the timezone output.

@thatsmydoing thatsmydoing changed the title Custom zone Custom zone formatting support Feb 9, 2023
@thatsmydoing
Copy link
Contributor Author

Theoretically, the logic for fixed offset timezones can simply reuse the one for custom zones but I thought that might be too much of a breaking change compared to the current approach of using IANA zones for whole hour offsets.

@icambron
Copy link
Member

icambron commented Mar 4, 2023

@thatsmydoing this is great. I think we can just merge this as-is. Thanks for the contribution!

@icambron icambron merged commit c9f75ec into moment:master Mar 4, 2023
1 check failed
@thatsmydoing thatsmydoing deleted the custom-zone branch March 6, 2023 05:58
brboi added a commit to odoo-dev/odoo that referenced this pull request Aug 30, 2023
**Changelog**

**3.4.2 (2023-08-26)**

- Fixes regression from 3.4.1 (moment/luxon#1493)

**3.4.1 (2023-08-23)**

- Fixes for regressions from 3.4.0
  (moment/luxon#1482 and moment/luxon#1488)

**3.4.0 (2023-08-08)**

- Fix type checking on input zones
- Fix Islamic months listing
- Fix normalize() for negative inputs

**3.3.0 (2023-03-03)**

- Fix off-by-one in Interval#count (moment/luxon#1308)
- Support formatting for custom zones (moment/luxon#1377)
- Fix parsing for narrow spaces (moment/luxon#1369)
- Handle leap year issue with AD 100 (moment/luxon#1390)
- Allow parsing of just an offset

**3.2.1 (2023-01-04)**

- Fix for RFC-2822 regex vulnerability
- Better handling of BCP tags with -x- extensions

**3.2.0 (2022-12-29)**

- Allow timeZone to be specified as an intl option
- Fix for diff's handling of end-of-month when crossing leap years
  (moment/luxon#1340)
- Add Interval.toLocaleString() (moment/luxon#1320)

**3.1.1 (2022-11-28)**

- Add Settings.twoDigitCutoffYear

**3.1.0 (2022-10-31)**

- Add Duration.rescale

**3.0.4 (2022-09-24)**

- Fix quarters in diffs (moment/luxon#1279)
- Export package.json in package (moment/luxon#1239)

**3.0.2 (2022-08-28)**

- Lots of doc changes
- Added DateTime.expandFormat
- Added support for custom conversion matrices in Durations
robodoo pushed a commit to odoo/odoo that referenced this pull request Sep 4, 2023
**Changelog**

**3.4.2 (2023-08-26)**

- Fixes regression from 3.4.1 (moment/luxon#1493)

**3.4.1 (2023-08-23)**

- Fixes for regressions from 3.4.0
  (moment/luxon#1482 and moment/luxon#1488)

**3.4.0 (2023-08-08)**

- Fix type checking on input zones
- Fix Islamic months listing
- Fix normalize() for negative inputs

**3.3.0 (2023-03-03)**

- Fix off-by-one in Interval#count (moment/luxon#1308)
- Support formatting for custom zones (moment/luxon#1377)
- Fix parsing for narrow spaces (moment/luxon#1369)
- Handle leap year issue with AD 100 (moment/luxon#1390)
- Allow parsing of just an offset

**3.2.1 (2023-01-04)**

- Fix for RFC-2822 regex vulnerability
- Better handling of BCP tags with -x- extensions

**3.2.0 (2022-12-29)**

- Allow timeZone to be specified as an intl option
- Fix for diff's handling of end-of-month when crossing leap years
  (moment/luxon#1340)
- Add Interval.toLocaleString() (moment/luxon#1320)

**3.1.1 (2022-11-28)**

- Add Settings.twoDigitCutoffYear

**3.1.0 (2022-10-31)**

- Add Duration.rescale

**3.0.4 (2022-09-24)**

- Fix quarters in diffs (moment/luxon#1279)
- Export package.json in package (moment/luxon#1239)

**3.0.2 (2022-08-28)**

- Lots of doc changes
- Added DateTime.expandFormat
- Added support for custom conversion matrices in Durations

closes #133599

Related: odoo/enterprise#46556
Signed-off-by: Luca Vitali (luvi) <luvi@odoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants