mistatwista
Tzdata initialization in phoenix (in unit testing)
Hello,
I have just started with elixir and phoenix recently with my pet project.
In code I am trying to use tzdata.
I have set the initialization of tzdata database in the config/test.exs
import Config
config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase
IO.puts("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
IO.inspect(DateTime.now("Europe/Stockholm"))
# .... other stuff
but it seems it is not properly initialized since i see in the test run
Running tests...
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
{:error, :utc_only_time_zone_database}
and my [doc] test failed:
1) doctest Scraper.WiredDayParser.parse_date!/1 (1) (Scraper.WiredDayParserTest)
test/scrapper/wired_day_parser_test.exs:4
** (FunctionClauseError) no function clause matching in DateTime.from_naive/3
The following arguments were given to DateTime.from_naive/3:
# 1
{:ok, ~N[2023-04-07 23:21:20]}
# 2
"Europe/Stockholm"
# 3
Tzdata.TimeZoneDatabase
Attempted function clauses (showing 3 out of 3):
def from_naive(naive_datetime, "Etc/UTC", _)
def from_naive(%{calendar: Calendar.ISO} = naive_datetime, time_zone, time_zone_database)
def from_naive(%{calendar: calendar} = naive_datetime, time_zone, time_zone_database) when calendar != Calendar.ISO
stacktrace:
(elixir 1.14.3) lib/calendar/datetime.ex:496: DateTime.from_naive/3
(elixir 1.14.3) lib/calendar/datetime.ex:618: DateTime.from_naive!/3
(for doctest at) lib/scraper/wired_dates_parser.ex:8: (test)
Appreciate if someone could give me a clue about what might be missed.
Marked As Solved
al2o3cr
Two separate issues:
-
files like
config/test.exsare loaded before the whole system is up; IIRC the TZ database isn’t available from them. They aren’t generally good places to “try out” code. -
your test failure appears to be caused by passing an
{:ok, %NaiveDateTime}tuple as the first argument toDateTime.from_naive!, when it expects only theNaiveDateTimestructure.
1
Popular in Questions
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> somethi...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
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
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
I have VueJS GUIs with the project generated using Webpack.
I have Elixir modules that will need to be used by the VueJS GUIs.
I forese...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Other popular topics
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
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including.
What is Phoenix LiveV...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









