spencerolson

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

spencerolson

Think I found a solution that I’m happy with, and I can do away with having to tinker with the Application configuration :slight_smile:

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 :slight_smile: 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)

Also Liked

spencerolson

spencerolson

For posterity, here’s the change I ended up with. If there’s no timezone configured, use Tz.TimeZoneDatabase, otherwise use the already-configured timezone database.

And i was able to simplify installation instructions and get rid of an Application config value :partying_face:

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement