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
base: master
Are you sure you want to change the base?
Conversation
@@ -1,15 +1,67 @@ | |||
var momentTimezoneJson = require("./latest.json"); | |||
const packedLatest = require('moment-timezone/data/packed/latest.json'); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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}) => { |
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}); | ||
}); | ||
|
||
latest.countries.forEach((country, i) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}); | ||
}); | ||
|
||
const sortFn = (a, b) => { |
There was a problem hiding this comment.
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 = [ |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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.