Skip to content

Commit

Permalink
Add condition for system setZone (#1206)
Browse files Browse the repository at this point in the history
  • Loading branch information
davkub committed Jul 9, 2022
1 parent 4817697 commit 5fdcfc8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/impl/zoneUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import FixedOffsetZone from "../zones/fixedOffsetZone.js";
import InvalidZone from "../zones/invalidZone.js";

import { isUndefined, isString, isNumber } from "./util.js";
import SystemZone from "../zones/systemZone.js";

export function normalizeZone(input, defaultZone) {
let offset;
Expand All @@ -17,7 +18,8 @@ export function normalizeZone(input, defaultZone) {
return input;
} else if (isString(input)) {
const lowered = input.toLowerCase();
if (lowered === "local" || lowered === "system") return defaultZone;
if (lowered === "default") return defaultZone;
else if (lowered === "local" || lowered === "system") return SystemZone.instance;
else if (lowered === "utc" || lowered === "gmt") return FixedOffsetZone.utcInstance;
else return FixedOffsetZone.parseSpecifier(lowered) || IANAZone.create(input);
} else if (isNumber(input)) {
Expand Down
9 changes: 7 additions & 2 deletions test/datetime/zone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@ test('DateTime#setZone accepts "local"', () => {
expect(zoned.offset).toBe(DateTime.local().offset);
});

test('DateTime#setZone accepts "system" and uses the default zone', () => {
test('DateTime#setZone accepts "system" and uses the system zone', () => {
const systemZone = Settings.defaultZone.name;
expect(DateTime.utc().setZone("system").zoneName).toBe(systemZone);
});

test('DateTime#setZone accepts "default" and uses the default zone', () => {
Helpers.withDefaultZone("Europe/Paris", () => {
expect(DateTime.utc().setZone("system").zoneName).toBe("Europe/Paris");
expect(DateTime.utc().setZone("default").zoneName).toBe("Europe/Paris");
});
});

Expand Down
8 changes: 5 additions & 3 deletions test/info/zones.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ test("Info.normalizeZone converts null and undefined to default Zone", () => {
expect(Info.normalizeZone(undefined)).toBe(Settings.defaultZone);
});

test("Info.normalizeZone converts local to default Zone", () => {
// Local zone no longer refers to default one but behaves as system
// As per Docker Container, zone is America/New_York
test("Info.normalizeZone converts local to system Zone", () => {
expect(Info.normalizeZone("local")).toBe(Settings.defaultZone);
Helpers.withDefaultZone("Europe/Paris", () => {
expect(Info.normalizeZone("local").name).toBe("Europe/Paris");
Helpers.withDefaultZone("America/New_York", () => {
expect(Info.normalizeZone("local").name).toBe("America/New_York");
});
});

0 comments on commit 5fdcfc8

Please sign in to comment.