jonotree

jonotree

I’m trying to use Tzdata module, and according to the Getting Started section of the hexdoc

, the following config should be used:

config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase

Issue 1
When trying to follow this I had the problem of having no config file in my project (generated using mix new projectname) - I’ve provisionally created config/config.exs at the root, with use Mix.Config at the top, based on previous example project. However, documentation about config states that depending on whether you want that the config info to influence the initial build, or be accessible at runtime, you should use put it in runtime.exs or config.exs.
In the case I’m not sure which is appropriate - should it be in config.exs?

Issue 2
Secondly, I’ve updated to a newer version of Elixir (1.13.3) since making the previous example project, and now I’m being warned that Mix.Config is deprecated.In order to migrate to the newer Config module, I want to understand what the line config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase actually does. Looking at the documentation of Mix.Config.config/3, I would expect the arguments to be: root element, key, options (keyword list?) - but here we have:
root element = Elixir
key = :time_zone_database
options(s) = Tzdata.TimeZoneDatabase

Specifying the options as Tzdata.TimeZoneDatabase surely does not pass for a keyword list, so what’s going on here?

Marked As Solved

cmo

cmo

You probably want that one in config.exs.

You often have these files:

config/
- config.exs
- dev.exs
- prod.exs
- runtime.exs
- test.exs

config.exs is your base config and others are imported afterwards, depending on the environment, like so:

# This file is responsible for configuring your application
# and its dependencies with the aid of the Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.

# General application configuration
import Config

... your config here ...

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"

If you’re using releases, runtime.exs will end up in the release directory, so you can edit it after the fact. The others will vanish, like magic (or be compiled).

All the config will end up in your Application env, which you can retrieve using Application.fetch_env/get_env and friends. Notice the typespec for Application.put_env is put_env(app(), key(), value(), timeout: timeout(), persistent: boolean()) :: :ok, where value() :: term().

Config.config/3 is config(root_key, key, opts). It talks about keyword lists, which may lead us to think we can only put keyword lists in there, but as we can see from our config files, and Application.put_env, we can jam just about anything in there. Typically it is either a single value or a keyword list.

Last Post!

jonotree

jonotree OP

I see, as you suggested I have got it working using config.exs.

Config is also now working using the module name as opposed to a keyword list - for some reason I was getting an error when using just the module name, but after adjusting a few places and retrying, it seems the source of the error was somewhere else. Thankyou!

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
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
perzanko
Do we have maintainer of absinthe-graphql/dataloader here? We have a PR that we’d like to merge to the library. Relatively small additive...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
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
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews