nikody

nikody

I found various topics discussing the differences and similarities between :naive_datetime and :utc_datetime, namely:

In addition, I looked through Ecto.Schema — Ecto v3.14.0, where it says:

All of those types [naive_datetime, naive_datetime_usec, utc_datetime, utc_datetime_usec] 
are represented by the same timestamp/datetime in the underlying data storage, 
the difference are in their precision and how the data is loaded into Elixir.

I’m guessing the difference in precision is related to the _usec datetime types.

But I’m still wondering - why does Phoenix use :naive_datetime by default for timestamps? From all these discussions I either get the impression that it does not matter or that it’s slightly better to use :utc_datetime. However, in this topic I’m not trying to start a conversation comparing the two like as much as understand the default choice for Phoenix.

Edit: Added link to the Ecto documentation, too.

Most Liked

peerreynders

peerreynders

In my view the difference is semantics.

  • :utc_datetime is very clear that UTC is it’s frame of reference
  • :naive_datetime retains ambiguity as to what the frame of reference is. It’s up to the application context to imply and/or supply the frame of reference.
    • In the absence of any other evidence UTC is the only sensible choice.
    • In the application context of being used as a Phoenix timestamp it is known to be UTC.

So just because it’s :naive_datetime doesn’t automatically imply it’s not UTC.


nikody

nikody OP

Thank you both for the replies once more, and, I must say, for your contributions to other topics too.

I noticed this comment by Michał Muskała, which also seems helpful for my question - Deprecation warning says to use :naive_datetime but I'd like to use :utc_datetime - #5 by michalmuskala

Just to clarify. The warning says to use :naive_datetime since that’s the type 
with exactly the same behaviour as the old Ecto.DateTime. 
The :utc_datetime has slightly different semantics.
peerreynders

peerreynders

You already linked to this

The reason why Ecto’s timestamps() are naive by default is backwards compatibility.

In what way doesn’t that address your question?

It is my impression that the core team by convention treats time data without a timezone as UTC.

Confusion typically arises with people coming from other backgrounds who may have been working with a different convention - assuming that timezone free data is recorded with reference to local server time or local client time - which may be immediately convenient in the local context but creates problems in a long term historical or global context.

Where Next? Top

Trending in Questions Top

RSP87
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
nseaSeb
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
RemyXRenard
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
velrest
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
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
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
FlyingNoodle
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 Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews