js-joda / js-joda-timezone

!This package is deprecated!
Other
27 stars 4 forks source link

Make packedJson available to allow zone database sharing with moment-timezone #29

Closed slavap closed 6 years ago

slavap commented 6 years ago

Add function/property to JSJodaTimezone to allow getting packed json zone database, then it will be possible using it with moment.tz.load()

slavap commented 6 years ago

I've fixed it manually in my project:

exports.default = function (jsJoda) {
    jsJoda.ZoneRulesProvider.getRules = _MomentZoneRulesProvider.MomentZoneRulesProvider.getRules;
    jsJoda.ZoneRulesProvider.getAvailableZoneIds = _MomentZoneRulesProvider.MomentZoneRulesProvider.getAvailableZoneIds;
    /*ADDED>>>*/ jsJoda.ZoneRulesProvider.TZDB = _latest2.default;
    (0, _systemDefaultZone2.default)(jsJoda.ZoneId);
    return jsJoda;
};

Then it's possible to call:

moment.tz.load(JSJoda.ZoneRulesProvider.TZDB); 

and get moment.tz working based on joda's IANA database.

pithu commented 6 years ago

Hello @slavap

thx for using js-joda and your feedback.

I guess your use case is, that you need moment and js-joda in the browser and you want save data transferred to the client, correct ? just for curiosity, what do you miss in js-joda-timezone what just moment.tz has?

Well, anyway, i agree that re-using the tzdb data is a valid use case and we can export it for further use.

BUT, the format of tzdb data is compatible to moment.tz.load() by accident and this might change in the future, because we are missing some information in the "moment style" data.

So i could mark the export as private (eg jsJoda.ZoneRulesProvider._TZDB), but there is no guarantee that the format change in a next major update. Would that help ?

slavap commented 6 years ago

@pithu one of the useful functions is moment.tz.guess(), which can use timezone database for searching appropriate timezone if browser does not report it. Also some external code depends on moment.tz and I don’t want to port it to joda. If it’s possible, please preserve compatibility with moment.tz database even if extending joda’s db, because it will be too painful to load two similar timezone databases. Private export should be fine, thank you.

pithu commented 6 years ago

@slavap, i just released a new version, can you please verify if it worx as expected. var name is JSJoda.ZoneRulesProvider._TZDB

slavap commented 6 years ago

@pithu Thanks, it's working fine.