Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argg 585 use moment timezone #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

nensidosari
Copy link
Owner

@nensidosari nensidosari commented Jun 21, 2023

https://skyscanner.atlassian.net/browse/ARGG-585

Note: This PR does not mean we want this code to live here, it is only here for the purpose of testing + demonstration of how this transformation code could look like.

There is a bit difference in the file size of the outcome, this seems to be mainly because of the data range that is provided with the packaged data in moment-timezone.

https://momentjs.com/timezone/ provides build or downloads that have a more customisable range that we might try using.

@@ -1,15 +1,67 @@
var momentTimezoneJson = require("./latest.json");
const packedLatest = require('moment-timezone/data/packed/latest.json');
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We get the latest data from moment-timezone, but unlike the recommendations of what iana-tz-data package used

Copy the unpacked generated latest.json over here.

We only have access to the packed latest file.

version: momentTimezoneJson.version,
zoneData: {}
};
function unpackAndUnlink(latest) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function used to do all the necessary transformations to unpack the packed data


momentTimezoneJson.zones.forEach(({name, abbrs, untils, offsets, isdsts}) => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is code from iana-tz-package itself used for transformation that is used further down in the code

return tree[item] || (tree[item] = {});
}, output.zoneData)[name.slice(-1)[0]] = {abbrs, untils, offsets, isdsts};
})
latest.links.forEach(link => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2023-06-22 at 07 47 44 This is how links look like, this function separates them and pushes them as a separate zone.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2023-06-22 at 07 55 42 This is how it looks like after being unpacked - each link becomes its own zone

});
});

latest.countries.forEach((country, i) => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how countries look like, this function separates them and pushes them as a separate country with all zones specified. also updates zones countries, by adding countryAlias to each countries zone

Screenshot 2023-06-22 at 07 56 45

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how it looks after being unpacked each country alias added to countries of a specific zone

Screenshot 2023-06-22 at 07 57 28

});
});

const sortFn = (a, b) => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary - I added this function to help me understand if we were getting all the data the way they were in the unpacked version that we get in moment-timezone code.

From my comparison it looks like we do get all the data, but there is a loot of data so can't put an 100% to it.

return a.replace('/', '').toLowerCase().localeCompare(b.replace('/', '').toLowerCase())
}

unpacked.zones = [
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still to help me understand if the data was the same, as the difference in sorting or where the objects were located were making it difficult in a huge file. We can discard this if we move on with this solution


const unpackedLatest = unpackAndUnlink(packedLatest);

var momentTimezoneJson = unpackedLatest;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest on the code from here is the transformation code from iana-tz-data package.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is way bigger than the one that we take from moment-timezone unpacked data.

The reason behind it?
Well so far from the comparison I could do, all the additions are because moment-timezone packed data provides us with a bigger range of data.

https://momentjs.com/timezone/ provides build or downloads that have a more customisable range that we might try using

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant