Skip to content

Commit

Permalink
allow timeZone to be specified as an intl option
Browse files Browse the repository at this point in the history
  • Loading branch information
icambron committed Dec 13, 2022
1 parent f8285c7 commit a6f2737
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/impl/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
}

Expand Down
12 changes: 11 additions & 1 deletion test/datetime/format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit a6f2737

Please sign in to comment.