exercism/elixir/gigasecond/lib/gigasecond.ex

18 lines
567 B
Elixir
Raw Normal View History

2024-07-02 17:06:46 +00:00
defmodule Gigasecond do
@gigasecond 1_000_000_000
@doc """
Calculate a date one billion seconds after an input date.
"""
@spec from({{pos_integer, pos_integer, pos_integer}, {pos_integer, pos_integer, pos_integer}}) ::
{{pos_integer, pos_integer, pos_integer}, {pos_integer, pos_integer, pos_integer}}
def from({{_year, _month, _day}, {_hours, _minutes, _seconds}} = erl_date_time) do
{:ok, from} =
NaiveDateTime.from_erl(erl_date_time)
from
|> NaiveDateTime.add(@gigasecond, :second)
|> NaiveDateTime.to_erl()
end
end