Koyomi.ISOWeek (Koyomi v0.2.1)

Copy Markdown View Source

ISO 8601 weeks: weeks start on Monday, and week 1 of a year is the week that holds the year's first Thursday. A week is written 2027-W11.

The week picker posts weeks in this form, and Koyomi.Week stores the Monday of the week in a :date column.

Summary

Functions

Reads YYYY-Www (or YYYYWww) into the Monday of the week.

The Monday of an ISO week, or :error when the year has no such week.

Writes the week of a day as YYYY-Www.

The ISO year and week number of a day.

The number of ISO weeks of a year: 52 or 53.

Functions

from_iso8601(text)

@spec from_iso8601(String.t()) :: {:ok, Date.t()} | :error

Reads YYYY-Www (or YYYYWww) into the Monday of the week.

Examples

iex> Koyomi.ISOWeek.from_iso8601("2027-W11")
{:ok, ~D[2027-03-15]}
iex> Koyomi.ISOWeek.from_iso8601("2027-W54")
:error

monday(year, week)

@spec monday(integer(), integer()) :: {:ok, Date.t()} | :error

The Monday of an ISO week, or :error when the year has no such week.

Examples

iex> Koyomi.ISOWeek.monday(2026, 53)
{:ok, ~D[2026-12-28]}
iex> Koyomi.ISOWeek.monday(2027, 53)
:error

to_iso8601(date)

@spec to_iso8601(Date.t()) :: String.t()

Writes the week of a day as YYYY-Www.

Examples

iex> Koyomi.ISOWeek.to_iso8601(~D[2027-03-17])
"2027-W11"

week(date)

@spec week(Date.t()) :: {integer(), 1..53}

The ISO year and week number of a day.

Examples

iex> Koyomi.ISOWeek.week(~D[2027-01-01])
{2026, 53}
iex> Koyomi.ISOWeek.week(~D[2027-03-15])
{2027, 11}

weeks_in_year(year)

@spec weeks_in_year(integer()) :: 52 | 53

The number of ISO weeks of a year: 52 or 53.

Examples

iex> Koyomi.ISOWeek.weeks_in_year(2026)
53