Time.new
You're seeing just the function
new
, go back to Time module for more information.
Link to this function
new(hour, minute, second, microsecond \\ {0, 0}, calendar \\ Calendar.ISO)
View SourceSpecs
new( Calendar.hour(), Calendar.minute(), Calendar.second(), Calendar.microsecond() | non_neg_integer(), Calendar.calendar() ) :: {:ok, t()} | {:error, atom()}
Builds a new time.
Expects all values to be integers. Returns {:ok, time}
if each
entry fits its appropriate range, returns {:error, reason}
otherwise.
Microseconds can also be given with a precision, which must be an integer between 0 and 6.
The built-in calendar does not support leap seconds.
Examples
iex> Time.new(0, 0, 0, 0)
{:ok, ~T[00:00:00.000000]}
iex> Time.new(23, 59, 59, 999_999)
{:ok, ~T[23:59:59.999999]}
iex> Time.new(24, 59, 59, 999_999)
{:error, :invalid_time}
iex> Time.new(23, 60, 59, 999_999)
{:error, :invalid_time}
iex> Time.new(23, 59, 60, 999_999)
{:error, :invalid_time}
iex> Time.new(23, 59, 59, 1_000_000)
{:error, :invalid_time}
# Invalid precision
Time.new(23, 59, 59, {999_999, 10})
{:error, :invalid_time}