BrightEyesDavid
I have a UTC datetime from a timestamptz PostgreSQL column, and am trying to:
- convert it to the user’s timezone;
- output a localised string representation for the frontend.
I’m trying to use DateTime for 1 and Cldr.DateTime for 2.
iex> {:ok, shifted} = DateTime.shift_zone(~U[2024-07-13 21:33:23.163097Z], "Europe/Berlin")
{:ok, #DateTime<2024-07-13 23:33:23.163097+02:00 CEST Europe/Berlin>}
However, Cldr.DateTime.to_string/2 doesn’t accept #DateTime<...>:
iex> {:ok, result} = Cldr.DateTime.to_string(shifted, "en-GB")
** (MatchError) no match of right hand side value: {:error, {ArgumentError, "Invalid DateTime. DateTime is a map that contains at least :year, :month, :day, :hour, :minute, :second and :calendar. Found: #DateTime<2024-07-13 23:33:23.163097+02:00 CEST Europe/Berlin Cldr.Calendar.Gregorian>"}}
(stdlib 4.3.1.3) erl_eval.erl:496: :erl_eval.expr/6
iex:3: (file)
I don’t know what #...<...> means, exactly, or how to convert it to a DateTime struct/map that Cldr.DateTime can use. Thanks.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
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
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #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)
belaustegui
Looks like you are calling Cldr.DateTime.to_string incorrectly.
The locale must be passed as a keyword list. This should work:
BrightEyesDavid
So the
#...<...>syntax is an alternative representation of a struct? I tried searching for information on that, but I must have done that wrong, too.dimitarvp
It’s simply human-friendly formatting, suitable for quickly taking a look.
LostKobrakai
See Inspect — Elixir v1.12.3
kip
I’ve published ex_cldr_dates_times version 2.20.2 that improves the error message when options are not provided as a keyword list. Using your example:
BrightEyesDavid
@dimitarvp, @LostKobrakai, thanks. So the use of # seems to be related to a comment marker, as the representation is not valid Elixir syntax. In 1.17’s documentation: Inspect — Elixir v1.17.2. That mentions that
#Name<...>tends to be used when there are private fields to hide. I guess in the case of DateTime it’s used for conciseness.@kip, thanks, and thanks very much for your libraries!