Skip to content

Conversation

@nwjlyons
Copy link
Contributor

@doc since: "1.9.0"
@spec utc_now(:microsecond | :millisecond | :second, Calendar.calendar()) :: t
def utc_now(time_unit, calendar) when time_unit in [:microsecond, :millisecond, :second] do
{:ok, _, time, microsecond} = Calendar.ISO.from_unix(:os.system_time(), :native)
Copy link
Member

Choose a reason for hiding this comment

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

I'd say we should pass the time unit as argument here:

Suggested change
{:ok, _, time, microsecond} = Calendar.ISO.from_unix(:os.system_time(), :native)
{:ok, _, time, microsecond} = Calendar.ISO.from_unix(:os.system_time(), time_unit)

and allow native as time unit, as done in NaiveDateTime.

Copy link
Member

Choose a reason for hiding this comment

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

This we don't need to truncate after the fact.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added :native. I also switched :os.system_time() for System.os_time(time_unit).

@josevalim josevalim merged commit c5c87a6 into elixir-lang:main Mar 25, 2025
10 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

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.

3 participants