hauks96
Does anyone have any experience with unit testing modules that need to be tested using DateTime objects with different timezones without having a real timezone database?
I am having trouble understanding how I would mock the timezone database in a way that would allow using methods such as DateTime.new!(Date.t, Time.t, Calendar.time_zone, Calendar.time_zone_database) without failing since the timezone database is not available.
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
Never tried what you need but I’d think that mock or patch will do the job.
hauks96
I know mock, but I don’t know how to mock a timezone database with it.
I don’t want to mock the functions I am calling, because I want to assert that the timezone conversions are taking place in the modules I am testing.
dimitarvp
Intuitively, I’d say just inspect Elixir’s source and see which timezone functions it uses when a timezone database is supplied?
Here’s what Elixir itself does when ultimately it gets down to calling a function from the timezone module: elixir/lib/elixir/lib/calendar/datetime.ex at 1a1eda52b46e37b0c77835e374c16ec64bb5c638 · elixir-lang/elixir · GitHub
Basically it calls its
time_zone_periods_from_wall_datetime/2function (first argument is datetime, second argument is a timezone).Another example in Elixir itself is how such a timezone database can be faked. Here: elixir/lib/elixir/test/elixir/calendar/fakes.exs at 1a1eda52b46e37b0c77835e374c16ec64bb5c638 · elixir-lang/elixir · GitHub
The link is to the above function but the entire module should be looked at.
You can combine that knowledge with either
mockorpatchso you have a local offline fake timezone database.dimitarvp
Just now saw your edit but it doesn’t change much. You can still make your mock respect timezone offsets.
Alternatively, I think you can just use a proper timezone database and instruct it to not do network requests.
tz has very configurable behaviour on when (or if?) to do automatic updates.
Here’s a link to the docs of tzdata that show you how to disable automatic updates.
hauks96
Thank you! I’ll take a look and share the results
LostKobrakai
Using past datetimes on non disputed regions should give you a rather stable timezone definition.
If you still need more control then you can use Mox with the time zone database behaviour and mock that.