Utility.Calendar (Portico/Z v0.1.0)
Functions to work with Dates, Times, etc.
Link to this section Summary
Link to this section Functions
current_academic_year()
Specs
current_academic_year() :: integer()
Return the current academic year / EXPLO season name
Flips to the next year on August 15.
Examples
iex> Utility.Calendar.current_academic_year() - 2021 > 0
format_date(map, opts)
Format a Date into EXPLO's favorite formats.
Also works on DateTime and NaiveDateTime structs, or any other struct with :month and :day keys.
See format_date_time/2 for details about options and formatting.
format_date_time(string_or_date, opts \\ [])
Format a datetime or datetime string into EXPLO's favorite formats.
Returns "" (empty string) if there's any parsing error.
Works with ISO8601 strings (such as those you get from saving NaiveDateTime or DateTime structs into a database), as well as working directly with NaiveDateTime and DateTime structs.
Options
You can pass the following opts:
:format- Use a different format from the default. Current options::am_pm-mm/dd hh:mm AM/PMin a 12-hour clock- Default format is
mm/dd hh:mmin a 24-hour clock
:pad(Boolean) - Throw a0in front of single-digit months, days, hours. Defaults totrue
Examples
iex> Utility.Calendar.format_date_time("2021-06-27T13:48:09.689291")
"06/27 13:48"
iex> Utility.Calendar.format_date_time("2021-06-27T13:48:09.689291", format: :am_pm, pad: false)
"6/27 1:48 PM"
iex> Utility.Calendar.format_date_time("2021-06-27T02:02:09.689291", format: :am_pm)
"06/27 02:02 AM"
iex> DateTime.new!(~D[2021-01-01], ~T[12:30:00], "America/New_York")
...> |> DateTime.to_iso8601
...> |> Utility.Calendar.format_date_time(format: :am_pm)
"01/01 12:30 PM"
iex> DateTime.new!(~D[2021-01-01], ~T[12:30:00], "America/New_York")
...> |> Utility.Calendar.format_date_time(format: :am_pm)
"01/01 12:30 PM"
iex> NaiveDateTime.new!(~D[2021-02-11], ~T[09:12:00])
...> |> Utility.Calendar.format_date_time(pad: false)
"2/11 9:12"
format_time(map, opts)
Format a Time into EXPLO's favorite formats.
Also works on DateTime and NaiveDateTime structs, or any other struct with :hour and :minute keys.
See format_date_time/2 for details about options and formatting.