tempo/month

Functions to use with the Month type in Tempo.

Example

import tempo/month
import tempo/date

pub fn get_next_month_name() {
  date.now_local()
  |> date.get_month
  |> month.next
  |> month.to_long_string
  // -> "November"
}

Functions

pub fn days(of month: Month, in year: Int) -> Int

Returns the number of days in a month.

Example

date.literal("2024-06-13")
|> date.get_month
|> month.days
// -> 30
date.literal("2024-12-03")
|> date.get_month
|> month.days
// -> 31
pub fn from_int(month: Int) -> Result(Month, Nil)

Gets a month from an integer representing the order of the month on the civil calendar.

Example

month.from_int(6)
// -> Ok(tempo.Jun)
month.from_int(13)
// -> Error(Nil)
pub fn from_long_string(month: String) -> Result(Month, Nil)

Gets a month from a long month string.

Example

month.from_long_string("June")
// -> Ok(tempo.Jun)
month.from_long_string("Jun")
// -> Error(Nil)
pub fn from_short_string(month: String) -> Result(Month, Nil)

Gets a month from a short month string.

Example

month.from_short_string("Jun")
// -> Ok(tempo.Jun)
month.from_short_string("June")
// -> Error(Nil)
pub fn from_string(month: String) -> Result(Month, Nil)

Gets a month from a month string.

Example

month.from_string("Jun")
// -> Ok(tempo.Jun)
month.from_string("June")
// -> Ok(tempo.Jun)
month.from_string("Hello")
// -> Error(Nil)
pub fn next(month: Month) -> Month

Returns the next month in the civil calendar.

Example

date.literal("2024-06-13")
|> date.get_month
|> month.next
// -> tempo.Jul
date.literal("2024-12-03")
|> date.get_month
|> month.next
// -> tempo.Jan
pub fn prior(month: Month) -> Month

Returns the previous month in the civil calendar.

Example

date.literal("2024-06-13")
|> date.get_month
|> month.prior
// -> tempo.May
date.literal("2024-01-03")
|> date.get_month
|> month.prior
// -> tempo.Dec
pub fn to_int(month: Month) -> Int

Returns a month’s number on the civil calendar.

Example

date.literal("2024-06-13")
|> date.get_month
|> month.to_int
// -> 6
pub fn to_long_string(month: Month) -> String

Returns a month’s long name.

Example

date.literal("2024-06-13")
|> date.get_month
|> month.to_short_string
// -> "June"
pub fn to_short_string(month: Month) -> String

Returns a month’s short name.

Example

date.literal("2024-06-13")
|> date.get_month
|> month.to_short_string
// -> "Jun"
Search Document