diff --git a/src/impl/locale.js b/src/impl/locale.js index 257907b76..d3cb34744 100644 --- a/src/impl/locale.js +++ b/src/impl/locale.js @@ -186,7 +186,7 @@ class PolyDateFormatter { constructor(dt, intl, opts) { this.opts = opts; - let z; + let z = undefined; if (dt.zone.isUniversal) { // UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like. // That is why fixed-offset TZ is set to that unless it is: @@ -222,9 +222,7 @@ class PolyDateFormatter { } const intlOpts = { ...this.opts }; - if (z) { - intlOpts.timeZone = z; - } + intlOpts.timeZone = intlOpts.timeZone || z; this.dtf = getCachedDTF(intl, intlOpts); } diff --git a/test/datetime/format.test.js b/test/datetime/format.test.js index 695a83aaf..823dce354 100644 --- a/test/datetime/format.test.js +++ b/test/datetime/format.test.js @@ -415,10 +415,20 @@ test("DateTime#toLocaleString uses locale-appropriate time formats", () => { expect(dt.reconfigure({ locale: "es" }).toLocaleString(DateTime.TIME_24_SIMPLE)).toBe("9:23"); }); +test("DateTime#toLocaleString() accepts a zone even when the zone is set", () => { + expect( + dt.toLocaleString({ + hour: "numeric", + minute: "numeric", + timeZoneName: "short", + timeZone: "America/Los_Angeles", + }) + ).toBe("2:23 AM PDT"); +}); + //------ // #resolvedLocaleOpts() //------ - test("DateTime#resolvedLocaleOpts returns a thing", () => { const res = DateTime.now().resolvedLocaleOptions();