mathieuprog / tz

Time zone support for Elixir
Apache License 2.0
147 stars 11 forks source link

Is it possible to make the custom data dir a runtime value? #11

Closed lud closed 2 years ago

lud commented 2 years ago

Currently it is set at compile time.

Would that be ok for the value to be fetched at runtime, so it can be set as an environment variable in production environments or docker containers?

Thank you

mathieuprog commented 2 years ago

I actually have no experience with builds. What about config/runtime.exs?

lud commented 2 years ago

That won't work because your have the following code directly in the module body:

@custom_data_dir Application.get_env(:tz, :data_dir)

So it is evaluated when the library is compiled, not when runtime is launched.

mathieuprog commented 2 years ago

What about changing that line to

defp custom_data_dir() do
  Application.get_env(:tz, :data_dir)
end
lud commented 2 years ago

Yep sure, that would work.

mathieuprog commented 2 years ago

Can you try it out and check if your deployments work with different config? And send a PR? Or are you certain this will just do?

lud commented 2 years ago

Sorry we switched to tzdata when we faced that problem, I have currently no app using tz.

mathieuprog commented 2 years ago

This has been added in version 0.21.1.

Note that tzdata has bugs, sometimes may return wrong times or raise errors. That's why I created this library in the first place, I would never have spent months writing it otherwise.

Only tz and time_zone_info output correct times.

lud commented 2 years ago

Hi,

Yes I know, that is why we used tz and I raised this issue but we needed to configure the custom dir at runtime to work well with our docker deployment. That was for CRON-like jobs, just dealing with 2022+ dates.

I'll try again tz on a future iteration but I honestly don't know when I will work on this project again.