-
Notifications
You must be signed in to change notification settings - Fork 103
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
Make JS TimeZone support easier to integrate #178
Comments
The JS timezone support does not seem that cumbersome—as you show, it's just four lines, listed in our README. Providing our own package for this, however, is not as straightforward as it seems. In JS, for example, there's sometimes the need to aggressively reduce the size of the package, given how it is transferred to the browser, so a reduced timezone database may be used: https://github.com/js-joda/js-joda/tree/master/packages/timezone#reducing-js-joda-timezone-file-size We haven't evaluated how much of a problem this is for Kotlin+JS projects, but if it is a problem, we would need to provide reduced-size packages as well. Additionally, the code is not ready for supporting timezone databases loaded from the outside, and we're not sure about the API for choosing which database to use—the system one, if present, or the loaded one, if present, or maybe something else?.. Should we publish a new library release each time a new timezone database is released? If so, we would need some automation for this. Etc. So, not at all simple. There are more pressing matters, like formatting, adding |
Absolutely, this is just a minor feature request. :) |
It would be useful if this information was much clearer in the documentation, I only worked out why my timezone lookups were failing from this ticket |
Workaround no longer worked for me in Kotlin 1.6.20 (IR compiler). This works: @JsModule("@js-joda/timezone")
@JsNonModule
private external object JsJodaTimeZoneModule
@EagerInitialization
@OptIn(ExperimentalStdlibApi::class)
@Suppress("unused")
private val init = JsJodaTimeZoneModule |
Strange, in my toy project where I smoke-test datetime, this is not required, JS-IR + 1.6.20 recognizes the time zones just fine with the old trick, when testing in both Node and the browsers. |
Might have been because the respective module is loaded dynamically in my project. |
Also, it only happened when deploying the final build including Webpack & terser optimizations. The library was then optimized away. |
Does the problem persist if you don't mark the |
Unfortunately I've got no time for additional tests here |
This is how I have it setup (
The generated js has
I've had problems like this with other libs and I find the best debugging path is to look at the generated code in build/js/packages |
For me, the instructions in the README are working for a debug build, but not in webpack release build. In the release build only, no time zones can be found. The workaround that worked for me is to add a reference to the timezone module in the function where I'm accessing it. I suspect the top-level one in the README is not getting loaded in release mode? val forceModuleImport = JsJodaTimeZoneModule
ZoneId.of(timezone) |
I experienced the same issue and did some further testing: making the val jsJodaTz public (instead of private) does not fix it. Accessing the property from the main function fixed it - e.g.
@EagerInitialization might be a fix: but I see this is already deprecated. Should this be filed as a case for keeping EagerInitialization? In the meantime: the README should be updated. I can make a pull request for that if it helps. |
In my case this changes helps for my js library @JsModule("@js-joda/timezone")
@JsNonModule
external object JsJodaTimeZoneModule
@JsExport // add export
val jsJodaTz = JsJodaTimeZoneModule // and public |
Could someone please provide a project where the code from the README isn't enough? I just tried creating another Kotlin/JS project, and everything works for me without |
Currently, in order to use time zones in JS you have to add an NPM dependency and custom code:
Would it be possible to just provide a kotlinx-datetime-timezones module which does both steps automatically, so all you need to do is add the module dependency? Then no extra code would be needed and in theory this module could also provide time zone databases for other platforms where you'd also need extra dependencies and init code.
The text was updated successfully, but these errors were encountered: