Skip to content

Commit a6f2737

Browse files
committed
allow timeZone to be specified as an intl option
1 parent f8285c7 commit a6f2737

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/impl/locale.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class PolyDateFormatter {
186186
constructor(dt, intl, opts) {
187187
this.opts = opts;
188188

189-
let z;
189+
let z = undefined;
190190
if (dt.zone.isUniversal) {
191191
// UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like.
192192
// That is why fixed-offset TZ is set to that unless it is:
@@ -222,9 +222,7 @@ class PolyDateFormatter {
222222
}
223223

224224
const intlOpts = { ...this.opts };
225-
if (z) {
226-
intlOpts.timeZone = z;
227-
}
225+
intlOpts.timeZone = intlOpts.timeZone || z;
228226
this.dtf = getCachedDTF(intl, intlOpts);
229227
}
230228

test/datetime/format.test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,20 @@ test("DateTime#toLocaleString uses locale-appropriate time formats", () => {
415415
expect(dt.reconfigure({ locale: "es" }).toLocaleString(DateTime.TIME_24_SIMPLE)).toBe("9:23");
416416
});
417417

418+
test("DateTime#toLocaleString() accepts a zone even when the zone is set", () => {
419+
expect(
420+
dt.toLocaleString({
421+
hour: "numeric",
422+
minute: "numeric",
423+
timeZoneName: "short",
424+
timeZone: "America/Los_Angeles",
425+
})
426+
).toBe("2:23 AM PDT");
427+
});
428+
418429
//------
419430
// #resolvedLocaleOpts()
420431
//------
421-
422432
test("DateTime#resolvedLocaleOpts returns a thing", () => {
423433
const res = DateTime.now().resolvedLocaleOptions();
424434

0 commit comments

Comments
 (0)