scriptorium/utils/date

Types

A date with 1-indexed years and days.

pub type Date {
  Date(year: Int, month: Month, day: Day)
}

Constructors

  • Date(year: Int, month: Month, day: Day)
pub type Month {
  Jan
  Feb
  Mar
  Apr
  May
  Jun
  Jul
  Aug
  Sep
  Oct
  Nov
  Dec
}

Constructors

  • Jan
  • Feb
  • Mar
  • Apr
  • May
  • Jun
  • Jul
  • Aug
  • Sep
  • Oct
  • Nov
  • Dec

Constants

pub const months: List(Month)

All months in order.

Functions

pub fn compare(a: Date, b: Date) -> Order

Compare if a is before (lower than) b.

pub fn days_in_month(month: Month, year: Int) -> Int

Get the number of days in a month in a given year.

pub fn format(date: Date) -> String

Format a date in the format “2 Aug 2024”.

pub fn format_iso(date: Date) -> String

Format a date in the ISO 8601 format.

pub fn is_valid_date(date: Date) -> Bool

Check if a given date is valid.

pub fn month_to_int(month: Month) -> Int

Convert a month to a 1-indexed int.

pub fn month_to_string(month: Month) -> String

Convert a month to an English month name string.

pub fn parse_month(month_int: Int) -> Result(Month, Nil)

Parse an integer into a month.

Search Document