sergio
Curious how you store your user’s timezone information to be able to send them an email at 12PM local time for example.
Assuming I default a dropdown with getTimezoneOffset clientside and allow the user to pick their timezone, what would be the best way to store this information?
Ideally whatever I save should be easy to use in Timex functions to calculate “schedule this Oban worker at 12PM user’s local time.”
Curious what you’ve guys done for this kind of issue in the past.
I could save the offset like:
timezone_offset: 360 # UTC-6 hours
Then schedule the job for tomorrow at 12pm local time:
timezone_offset = user.timezone_offset # 360
schedule_time =
Timex.now()
|> Timex.shift(days: 1)
|> Timex.beginning_of_day()
|> Timex.shift(hours: 12)
|> Timex.shift(minutes: timezone_offset)
Oban.insert!(%Oban.Job{
worker: MyWorker,
scheduled_at: schedule_time
})
Any sharp edges I’m not considering before going this route?
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
The obligatory hello world thread!
Who are you and where are you from? :stuck_out_tongue:
New
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project.
My initial shotgu...
New
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog
It says that Fly is going all-in on sprites, which is a worry ...
New
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using.
We’re particularly inte...
New
Other Trending Topics
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
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
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
Chat & Discussions>Discussions
Latest on Elixir Forum
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
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 7 of 7 Posts
kokolegorille
tz can do it for You…
You provide a naive_datetime (virtual attribute), a timezone, and tz can handle offset and utc itself.
UPDATE: Ouups, I think it’s tzdata that does this
In fact, it’s tz_datetime, sorry
LostKobrakai
Timezone offsets are not timezones. It tells you almost nothing about the future. Sure the offset might be X today for the user, but how do you know the same still applies tomorrow?
You need the timezone, not just the offset, to do this stuff reliably. I’d also suggest to stick to elixir core APIs nowadays, as besides parsing they can do everything you need. There’s no need to attempt to build your own timezone handling.
sergio
That’s interesting and makes sense. Are you saying Elixirs core will keep up to date with time zone changes so I should rely on them?
LostKobrakai
No, you need a library like tz or tzdata to bring in a database of timezones, but elixir itself brings all the necessary APIs to make use of those databases.
LostKobrakai
To get a little more concrete than my last post:
Timex.nowmight already return a different date than the current date of the user (australia is long in the new year before midnight in the usa)tfwright
I store the timezone name (e.g.
America/Chicago) inusers.time_zoneand use that when using Elixir DateTime functions, and they also work with postgres’sAT TIME ZONEin case you want to query users against a given time or datetime.dimitarvp
Ha, didn’t know the part about Postgres, thank you.