Skip to content

Commit

Permalink
Merge pull request #6 from sgomes/fix-links-from-unknown-timezones
Browse files Browse the repository at this point in the history
Ensure there are no links from unknown timezones.
  • Loading branch information
gilmoreorless authored Feb 24, 2019
2 parents 5f899d6 + 2b1332e commit d41cd47
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "2017"
"ecmaVersion": 2018
},
"env": {
"es6": true,
Expand Down
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ function filterData(tzdata, config, file) {
const filteredData = moment.tz.filterLinkPack(
{
version: tzdata.version,
zones: newZonesData,
links: newLinksData.map(link => link.join('|')),
zones: newLinksData.reduce((zones, link) => {
const newEntry = { ...newZonesData.find(z => z.name === link[0]) };
newEntry.name = link[1];
zones.push(newEntry);
return zones;
}, newZonesData ),
links: [],
},
startYear,
endYear
Expand Down
11 changes: 11 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ describe('usage', () => {
const zoneCount = data.zones.length + data.links.length;
assert(zoneCount === moment.tz.names().length);
});

it("does not include links from undefined timezones", async () => {
const { data } = await buildWebpack({
startYear: 2000
});
for (const link of data.links) {
const from = link.split('|')[0];
const matchingZone = data.zones.find(zone => zone.startsWith(from));
assert.notEqual(matchingZone, undefined, `'${from}' not in zones`);
}
});
});

describe('caching', () => {
Expand Down

0 comments on commit d41cd47

Please sign in to comment.