-
Notifications
You must be signed in to change notification settings - Fork 730
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
Conversation
z = "UTC"; | ||
if (opts.timeZoneName) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
ac0bcb6
to
5877f93
Compare
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. |
5877f93
to
0755762
Compare
@thatsmydoing this is great. I think we can just merge this as-is. Thanks for the contribution! |
**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
**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>
This addresses #1363
This addresses a couple of bugs related to non-IANA timezone formatting
timeZoneName
is not set and partial hour fixed-offset zones don't handle this properlyformatToParts