1defmodule Calendar.Time.Format do
2  alias Calendar.Strftime
3
4  @doc """
5  Format a time as ISO 8601 extended format
6
7  ## Examples
8
9      iex> Calendar.Time.from_erl!({20, 5, 18}) |> Calendar.Time.Format.iso8601
10      "20:05:18"
11  """
12  def iso8601(time) do
13    time
14    |> contained_time
15    |> Strftime.strftime!("%H:%M:%S")
16  end
17
18  @doc """
19  Format as ISO 8601 Basic
20
21  # Examples
22
23      iex> Calendar.Time.from_erl!({20, 10, 20}) |> Calendar.Time.Format.iso_8601_basic
24      "201020"
25
26  """
27  def iso_8601_basic(time) do
28    time = time |> contained_time
29    Strftime.strftime!(time, "%H%M%S")
30  end
31
32  defp contained_time(time_container) do
33    Calendar.ContainsTime.time_struct(time_container)
34  end
35end
36