Skip to content

Commit

Permalink
stop specifying Etc/GMT* zones
Browse files Browse the repository at this point in the history
  • Loading branch information
icambron committed Nov 5, 2021
1 parent b080889 commit 7eca41f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 44 deletions.
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/impl/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,4 @@ export function timeObject(obj) {
return pick(obj, ["hour", "minute", "second", "millisecond"]);
}

export const ianaRegex = /[A-Za-z_+-]{1,256}(:?\/[A-Za-z_+-]{1,256}(\/[A-Za-z_+-]{1,256})?)?/;
export const ianaRegex = /[A-Za-z_+-]{1,256}(:?\/[A-Za-z0-9_+-]{1,256}(\/[A-Za-z0-9_+-]{1,256})?)?/;
5 changes: 1 addition & 4 deletions src/impl/zoneUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ export function normalizeZone(input, defaultZone) {
const lowered = input.toLowerCase();
if (lowered === "local" || lowered === "system") return defaultZone;
else if (lowered === "utc" || lowered === "gmt") return FixedOffsetZone.utcInstance;
else if ((offset = IANAZone.parseGMTOffset(input)) != null) {
// handle Etc/GMT-4, which V8 chokes on
return FixedOffsetZone.instance(offset);
} else if (IANAZone.isValidSpecifier(lowered)) return IANAZone.create(input);
else if (IANAZone.isValidSpecifier(lowered)) return IANAZone.create(input);
else return FixedOffsetZone.parseSpecifier(lowered) || new InvalidZone(input);
} else if (isNumber(input)) {
return FixedOffsetZone.instance(input);
Expand Down
12 changes: 0 additions & 12 deletions src/zones/IANAZone.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,6 @@ export default class IANAZone extends Zone {
}
}

// Etc/GMT+8 -> -480
/** @ignore */
static parseGMTOffset(specifier) {
if (specifier) {
const match = specifier.match(/^Etc\/GMT(0|[+-]\d{1,2})$/i);
if (match) {
return -60 * parseInt(match[1]);
}
}
return null;
}

constructor(name) {
super();
/** @private **/
Expand Down
17 changes: 10 additions & 7 deletions test/datetime/zone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,16 @@ test("DateTime#offsetNameShort returns null for invalid times", () => {
//------
// Etc/GMT zones
//------
test("Etc/GMT zones work even though V8 does not support them", () => {
let zoned = DateTime.local().setZone("Etc/GMT+8");
expect(zoned.zoneName).toBe("UTC-8");
zoned = DateTime.local().setZone("Etc/GMT-5");
expect(zoned.zoneName).toBe("UTC+5");
zoned = DateTime.local().setZone("Etc/GMT-0");
expect(zoned.zoneName).toBe("UTC");
test.each([
["Etc/GMT+8", -8],
["Etc/GMT-5", 5],
["Etc/GMT", 0],
["Etc/GMT-0", 0],
["Etc/GMT", 0],
])("Etc/GMTx zones now work natively", (zone, expectedOffset) => {
let zoned = dt().setZone(zone);
expect(zoned.isValid).toBe(true);
expect(zoned.offset).toEqual(expectedOffset * 60);
});

//------
Expand Down
4 changes: 2 additions & 2 deletions test/info/zones.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ test.each([
["System", SystemZone.instance],
["UTC", FixedOffsetZone.utcInstance],
["GMT", FixedOffsetZone.utcInstance],
["Etc/GMT+5", FixedOffsetZone.instance(-5 * 60)],
["Etc/GMT-10", FixedOffsetZone.instance(+10 * 60)],
["Etc/GMT+5", new IANAZone("Etc/GMT+5")],
["Etc/GMT-10", new IANAZone("Etc/GMT-10")],
["Europe/Paris", new IANAZone("Europe/Paris")],
[0, FixedOffsetZone.utcInstance],
[3, FixedOffsetZone.instance(3)],
Expand Down
19 changes: 4 additions & 15 deletions test/zones/IANA.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ test("IANAZone.isValidSpecifier", () => {
expect(IANAZone.isValidSpecifier("America/New_York")).toBe(true);
expect(IANAZone.isValidSpecifier("Fantasia/Castle")).toBe(true);
expect(IANAZone.isValidSpecifier("Sport~~blorp")).toBe(false);
expect(IANAZone.isValidSpecifier("Etc/GMT+8")).toBe(true);
expect(IANAZone.isValidSpecifier("Etc/GMT-8")).toBe(true);
expect(IANAZone.isValidSpecifier("Etc/GMT-0")).toBe(true);
expect(IANAZone.isValidSpecifier("Etc/GMT-1")).toBe(true);
expect(IANAZone.isValidSpecifier(null)).toBe(false);
});

Expand All @@ -34,21 +38,6 @@ test("IANAZone.isValidZone", () => {
expect(IANAZone.isValidZone(4)).toBe(false);
});

test("IANAZone.parseGMTOffset returns a number for a valid input", () => {
expect(IANAZone.parseGMTOffset("Etc/GMT+8")).toBe(-480);
expect(IANAZone.parseGMTOffset("Etc/GMT+0")).toBe(-0);
expect(IANAZone.parseGMTOffset("Etc/GMT-0")).toBe(+0);
expect(IANAZone.parseGMTOffset("Etc/GMT0")).toBe(-0);
});

test("IANAZone.parseGMTOffset returns null for invalid input", () => {
expect(IANAZone.parseGMTOffset()).toBe(null);
expect(IANAZone.parseGMTOffset(null)).toBe(null);
expect(IANAZone.parseGMTOffset("")).toBe(null);
expect(IANAZone.parseGMTOffset("foo")).toBe(null);
expect(IANAZone.parseGMTOffset("Etc/GMT+blorp")).toBe(null);
});

test("IANAZone.type returns a static string", () => {
expect(new IANAZone("America/Santiago").type).toBe("iana");
expect(new IANAZone("America/Blorp").type).toBe("iana");
Expand Down

0 comments on commit 7eca41f

Please sign in to comment.