Skip to content

Browser compatiblty #12

Description

@gungun974

Hoi !

I'm working on my version 2 of intldate. It's a gleam library now inspired from Intl.DateTimeFormat() to format date while respecting human localization. So for my library I did the hard work of figuring out how to exploit the locale data and generate the date but by default gleam_time don't handle IANA timezone.

That's where I found tzifwhich was exactly what I was looking for and everything was perfect for my Erlang support.
Than I tried to run my project with lustre in the browser and that's where something went wrong...

This library is depending on simplifile for loading the tzdata from the OS which is great but that's mean in a browser you don't have access to node:fs. And gleam when you compiled something it will always wrote imports for everything so when the lustre bundle is executed, it will traverse my code, tzif (even if it's never used), simplifile and finally node:fs

Image

I know some ugly technique to solved this issue by making some ugly @external(erlang, ...) to prevent gleam importing my depending code of tzif but that's not the best solution and also this also bite me in my public API where I wanted to provide a intldate.set_time_zone_database(db: database.TzDatabase) for the user to provide an existing TzDatabase globally.

Now in term of solution to this browser incompatibly I can see only one way. Make tzif a sans-io library.
Like you publish on hexpm another library that depend on tzif for providing database.load_from_os() so tzif.
This mean the user can either choose to add this extra dependency for doing the system way or they could use alternate package like zones
But this is a breaking change sadly 😔

Anyway that's my story.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions