spencerolson

spencerolson

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!

Showing Posts 1 to 3

spencerolson

spencerolson OP

To add a bit more: I understand that in general I should avoid using Application configuration for libraries, however I’m not sure how else I’m going to ensure a timezone database is configured for Elixir when this library is run as an escript.

As an alternative, it looks like the Time zone database docs suggests I can call

Calendar.put_time_zone_database(Tz.TimeZoneDatabase)

which I think would solve my problem, however:

  1. I’m not sure where it would make sense to put that call
  2. That method internally calls Application.put_env(:elixir, :time_zone_database, database) and I’m not sure if it’s a good idea to be modifying the Application config at runtime (I’m guessing the answer is “no”).
spencerolson

spencerolson OP

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.20.2

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)

spencerolson

spencerolson OP

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:

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews