Skip to content

Commit da671de

Browse files
authored
Update Time.add message about units (#13121)
1 parent df66d88 commit da671de

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/elixir/lib/calendar/time.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,12 @@ defmodule Time do
515515

516516
def add(%{calendar: calendar, microsecond: {_, precision}} = time, amount_to_add, unit)
517517
when is_integer(amount_to_add) do
518+
if not is_integer(unit) and
519+
unit not in ~w(second millisecond microsecond nanosecond)a do
520+
raise ArgumentError,
521+
"unsupported time unit. Expected :hour, :minute, :second, :millisecond, :microsecond, :nanosecond, or a positive integer, got #{inspect(unit)}"
522+
end
523+
518524
amount_to_add = System.convert_time_unit(amount_to_add, unit, :microsecond)
519525
total = time_to_microseconds(time) + amount_to_add
520526
parts = Integer.mod(total, @parts_per_day)

0 commit comments

Comments
 (0)