spencerolson
Mix.escript.install and config/config.exs
Hi all!
I am fairly new to the elixir ecosystem and I’m working on my first library, weather. It’s a simple library that fetches and displays weather information, and it’s packaged as an escript.
In order to support displaying times in the correct zone for the weather data, I’ve added:
config :elixir, :time_zone_database, Tz.TimeZoneDatabase
to my config/config.exs.
Something strange I’ve noticed: when I install the escript via hex, the times are returned in UTC which leads me to believe the config.exs is not being evaluated.
$ mix escript.install hex weather 0.3.7
$ weather --test clear
🌞 10:17AM | 🌚 1:25AM
# THESE ARE UTC TIMES. THEY SHOULD BE 3PM, 6PM, 9PM,12AM,3AM
76° ⬇ 74° ⬇ 64° ⬇ 60° ⬇ 58°
8PM 11PM 2AM 5AM 8AM
77° | scattered clouds | 37% humidity
However, when installing via github, the times are reported in their correct zone, leading me to believe the config.exs is being evaluated in that case:
$ mix escript.install github spencerolson/weather tag v0.3.7
$ weather --test clear
🌞 5:17AM | 🌚 8:25PM
# THESE TIMES ARE IN THE CORRECT ZONE
76° ⬇ 74° ⬇ 64° ⬇ 60° ⬇ 58°
3PM 6PM 9PM 12AM 3AM
77° | scattered clouds | 37% humidity
Can someone help me understand what’s going on? Is it expected that I’d get different results when installing the escript from different locations? I’ve also tried installing without specifying a tag, and I run into the same issues.
Thanks in advance!
Marked As Solved
spencerolson
Think I found a solution that I’m happy with, and I can do away with having to tinker with the Application configuration ![]()
I’ll change my call to DateTime.shift_zone/3 here to make use of the third argument I can pass which specifies a Time zone database
DateTime — Elixir v1.17.3
And to answer my own question about the differences between github + hex, it appears that on hex the config.exs file isn’t present (which makes sense, because configs of dependencies are not used so it has no reason to store them)







