Skip to content

Conversation

@viniciusmuller
Copy link
Contributor

This pull request adds support for passing a time unit to NaiveDateTime and DateTime's utc_now/1 and creates an alternative utc_now/2 that accepts both a custom time unit and calendar.

Closes #12557

Comment on lines +180 to +181
If you want the current time in Unix seconds,
use `System.os_time/1` instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should say this, because you can use os_time/1 for microsecond/millisecond/nanosecond times as well, and because you can still use utc_now/1 for that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a standard text we have in all utc_now functions because people often do DateTime.utc_now() |> to_unix :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaah, gotcha!

Copy link
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @viniciusmuller, I have dropped some comments.

The main idea is too not use truncate and instead generate the correct version upfront. To do this, make utc_now/2 be the "canonical function" and have utc_now/1 call utc_now/2 accordingly.

viniciusmuller and others added 4 commits May 11, 2023 09:21
Co-authored-by: José Valim <jose.valim@gmail.com>
Co-authored-by: José Valim <jose.valim@gmail.com>
Co-authored-by: José Valim <jose.valim@gmail.com>
viniciusmuller and others added 3 commits May 11, 2023 09:47
Co-authored-by: José Valim <jose.valim@gmail.com>
Co-authored-by: José Valim <jose.valim@gmail.com>
@josevalim josevalim merged commit eb089d2 into elixir-lang:main May 11, 2023
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

michallepicki added a commit to michallepicki/elixir that referenced this pull request May 12, 2023
since elixir-lang#12558
it is also being called with :native as the time_unit
josevalim pushed a commit that referenced this pull request May 12, 2023
since #12558
it is also being called with :native as the time_unit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Support DateTime/NaiveDateTime.utc_now(time_unit_or_precision)

3 participants