-
Notifications
You must be signed in to change notification settings - Fork 837
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
Decouple moment-timezone from tzdata #369
Comments
There are already instructions for downloading data from a new tzdb version and packaging that data with any version of the code. So you could just download the version of the code you've been using previously and use the scripts to re-package that code with new data. It's also possible to use the no-data build of the library and then call Is there anything else we could provide to better serve your use case here? |
Suggestion from @schmod:
|
Both of those suggestions effectively fork moment-timezone because we need to manage either moment-timezone+updated tzdata or package the TZ data and some code to force the loading of that tzdata. That said, you're suggestions are workable for now and much appreciated. Thanks! |
I don't think a fork is necessary. The only question would be how to version the bundled builds. Right now, I think that we also need to consider that the implicit bundling of the library+data (which is very succinctly summarized in |
I'd be fine with distributing We may need some control over acceptable versions of the dependency, such as if we were to ever change the data format, but I think is is easily doable with npm. WRT heaviness - It's no big deal for a node.js user to take on the entire data set, which is why the current npm package includes it. Browser users do indeed have different requirements though. Ideally, only the minimal data necessary for the application would be included, but clearly folks tend to just use the whole thing. The moment-timezone docs haven't kept up with the newfangled ways the folks use package managers to download code, and frankly - neither have I. Please help me understand how changing what's in the npm package would affect browser-based users, and how we might be able to deliver different code to each environment with the same sets of packages. Are there other approaches we should consider? Thanks. |
I'm a strong proponent of @mj1856's solution. |
The big problem is that There are a few options we can take:
In my opinion, any solution should satisfy the following criteria:
Now, the elephants in the room:
Worse still, There may not be any good solutions to these issues -- I suspect that many developers would find it unreasonable to need to call |
We should finish the work cleaning up the moment-timezone interface and how it interacts with moment core. That would clean up a lot of the concerns about the mutation of the core. |
A possible compromise: The default export of It could be used as follows: const tzdata = require('moment-timezone-data');
const moment = require('moment-timezone')(tzdata); From there, we could extend this to resemble a builder pattern, moving the const moment = require('moment-timezone')
.add('America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0')
.add('America/New_York|EST EDT|50 40|0101|1Lz50 1zb0 Op0')
(); We could also place an extension point here to allow users to define an asynchronous loader: const moment = require('moment-timezone')
.add('America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0') // I know I need this one.
.fallback(function(year, zone, cb){
var decade = +year.toPrecision(3);
var url = "http://example.com/locales/tz/" + decade + "/" + zone + ".json";
fetch(url).then( response => cb(response.json) );
})(); (This would admittedly require all of the With this pattern, there should be no surprises at runtime, because instances of the However, there are some drawbacks:
|
@maggiepint -- That sounds good. I agree that this is the best place to start before we tackle the other issues at hand. |
@schmod Can I find some updates on this somewhere? |
+1 |
The coupling of moment-timezone with tzdata significantly increases the test burden when we simply want to update tzdata.
I'm open taking this work on myself if an approach can be agreed upon.
The text was updated successfully, but these errors were encountered: