I recently discovered the wonderful ~U sigil that can be used to create DateTime variables. However, what’s confusing to me is that you’d never know from looking at the result that you were in fact dealing with a %DateTime{} struct. For example:
Sigils are an input only construction that are executed at compile time.
Structs commonly support the Inspect protocol.
And its a common convention that structs that can be built with a sigil also use a sigil string as their inspect output. Because then when you copy/paste the inspected output into iex it will just work.
When you put the three points together you get the situation you describe. But there’s no magic going on. Just the output of the inspect protocol matching the sigil format.
You can force a different output in iex with the :structs option:
I typically convert the struct into a map so that I can see all the key/value pairs. Luckily elixir has a nice built in function Map.from_struct/1 which will do exactly what you think it will. The result for the datetime that you’ve referenced would look something like