Utility.Calendar (Portico/Z v0.1.0)

Functions to work with Dates, Times, etc.

Link to this section Summary

Functions

Return the current academic year / EXPLO season name

Format a Date into EXPLO's favorite formats.

Format a datetime or datetime string into EXPLO's favorite formats.

Format a Time into EXPLO's favorite formats.

Link to this section Functions

Link to this function

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
Link to this function

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.

Link to this function

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/PM in a 12-hour clock
    • Default format is mm/dd hh:mm in a 24-hour clock
  • :pad (Boolean) - Throw a 0 in front of single-digit months, days, hours. Defaults to true

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"
Link to this function

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.