Skip to content

Commit

Permalink
fix(@formatjs/intl-datetimeformat): handle Etc/GMT[+-]X, fix #2609
Browse files Browse the repository at this point in the history
  • Loading branch information
longlho committed Feb 21, 2021
1 parent a0baae3 commit 7ddc417
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -151,6 +151,7 @@
"@typescript-eslint/no-object-literal-type-assertion": 0,
"@typescript-eslint/no-unused-vars": 0,
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/no-this-alias": 0,
"import/dynamic-import-chunkname": "error",
"import/no-cycle": "error",
"import/no-duplicates": "error",
Expand Down
42 changes: 41 additions & 1 deletion packages/intl-datetimeformat/scripts/process-zdump.ts
Expand Up @@ -344,6 +344,46 @@ function processZone(
}
}

const SPECIAL_CASES = [
'Etc/GMT-14',
'Etc/GMT-13',
'Etc/GMT-12',
'Etc/GMT-11',
'Etc/GMT-10',
'Etc/GMT-9',
'Etc/GMT-8',
'Etc/GMT-7',
'Etc/GMT-6',
'Etc/GMT-5',
'Etc/GMT-4',
'Etc/GMT-3',
'Etc/GMT-2',
'Etc/GMT-1',
'Etc/GMT+1',
'Etc/GMT+2',
'Etc/GMT+3',
'Etc/GMT+4',
'Etc/GMT+5',
'Etc/GMT+6',
'Etc/GMT+7',
'Etc/GMT+8',
'Etc/GMT+9',
'Etc/GMT+10',
'Etc/GMT+11',
'Etc/GMT+12',
].map(tz => {
const offsetInHours = tz.split(/([-+]\d{1,2})/)[1];
const offsetInHoursNum = +offsetInHours;
const abbrv =
offsetInHoursNum > 0
? `GMT-${offsetInHoursNum}`
: `GMT+${-offsetInHoursNum}`;

return `zic/${tz} Mon Jan 1 00:00:00 0000 UTC = doesnotmatter ${abbrv} isdst=0 gmtoff=${
-offsetInHoursNum * 3600
}`;
});

async function main(args: minimist.ParsedArgs) {
const {_: files, polyfill, output, golden} = args;
const inputs = files.slice(2);
Expand All @@ -362,7 +402,7 @@ async function main(args: minimist.ParsedArgs) {
inputs.map((input: string) => readFile(input, 'utf8'))
);

processZone(contents.join('\n'), data, golden);
processZone([contents, ...SPECIAL_CASES].join('\n'), data, golden);

if (polyfill) {
outputFileSync(
Expand Down
4 changes: 2 additions & 2 deletions packages/intl-datetimeformat/src/core.ts
Expand Up @@ -248,7 +248,7 @@ defineProperty(DateTimeFormat.prototype, 'formatRangeToParts', {
startDate: number | Date,
endDate: number | Date
) {
let dtf = this;
const dtf = this;
if (typeof dtf !== 'object') {
throw new TypeError();
}
Expand All @@ -271,7 +271,7 @@ defineProperty(DateTimeFormat.prototype, 'formatRange', {
startDate: number | Date,
endDate: number | Date
) {
let dtf = this;
const dtf = this;
if (typeof dtf !== 'object') {
throw new TypeError();
}
Expand Down

0 comments on commit 7ddc417

Please sign in to comment.