- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.5k
          Modify Time.utc_now/1 to allow truncation and add Time.utc_now/2
          #14367
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
  
    Modify Time.utc_now/1 to allow truncation and add Time.utc_now/2
  
  #14367
              Conversation
        
          
                lib/elixir/lib/calendar/time.ex
              
                Outdated
          
        
      | @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) | 
There was a problem hiding this comment.
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:
| {: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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
Co-authored-by: José Valim <[email protected]>
Co-authored-by: Jean Klingler <[email protected]>
| 💚 💙 💜 💛 ❤️ | 
From https://groups.google.com/g/elixir-lang-core/c/KvOYiBk1j1Q