tempo/month
Functions to use with the Month type in Tempo.
The months here are the twelve months of the Gregorian calendar, in their Gregorian order, and their names are the English ones. Month lengths follow the Gregorian rules, including the leap year rule for February.
Values
pub fn days(of month: calendar.Month, in year: Int) -> Int
Returns the number of days in a month of the proleptic Gregorian calendar. The year is required because February has 29 days in a Gregorian leap year and 28 otherwise.
Any year value is accepted, not just the 1000 to 9999 range that the
tempo/date constructors are limited to.
Example
date.literal("2024-06-13")
|> date.get_month
|> month.days
// -> 30
date.literal("2024-12-03")
|> date.get_month
|> month.days
// -> 31
month.days(calendar.February, in: 2024)
// -> 29
month.days(calendar.February, in: 1900)
// -> 28
pub fn from_int(month: Int) -> Result(calendar.Month, Nil)
Gets a month from an integer representing the order of the month on the Gregorian calendar, so 1 for January through 12 for December. Any value outside 1 to 12 returns an error.
Example
month.from_int(6)
// -> Ok(tempo.Jun)
month.from_int(13)
// -> Error(Nil)
pub fn from_long_string(
month: String,
) -> Result(calendar.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(calendar.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(calendar.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 to_int(month: calendar.Month) -> Int
Returns a month’s number on the Gregorian calendar, from 1 for January through 12 for December.
Example
date.literal("2024-06-13")
|> date.get_month
|> month.to_int
// -> 6
pub fn to_long_string(month: calendar.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: calendar.Month) -> String
Returns a month’s short name.
Example
date.literal("2024-06-13")
|> date.get_month
|> month.to_short_string
// -> "Jun"