datebook/date

Utility functions for gleam/time’s calendar.Date.

Values

pub fn next(date: calendar.Date) -> calendar.Date

Returns the next date for a given Date.

Will return a nonsensical result if the provided Date is not valid. Validate it with calendar.is_valid_date first!

Examples

next(calendar.Date(2026, calendar.March, 22))
// -> calendar.Date(2026, calendar.March, 23)
pub fn previous(date: calendar.Date) -> calendar.Date

Returns the previous date for a given Date.

Will return a nonsensical result if the provided Date is not valid. Validate it with calendar.is_valid_date first!

Examples

previous(calendar.Date(2026, calendar.March, 22))
// -> calendar.Date(2026, calendar.March, 21)
pub fn range(
  from: calendar.Date,
  to: calendar.Date,
) -> Result(List(calendar.Date), Nil)

Returns the inclusive list of dates between from and to.

Fails if from > to and when from or to are invalid dates.

Examples

range(Date(2026, March, 29), Date(2026, April, 2))
// -> Ok([
//   Date(2026, March, 29),
//   Date(2026, March, 30),
//   Date(2026, March, 31),
//   Date(2026, April, 1),
//   Date(2026, April, 2),
// ])
range(Date(2026, March, 22), Date(2026, March, 22))
// -> Ok([Date(2026, March, 22)])
range(Date(2026, March, 22), Date(2026, March, 21))
// -> Error(Nil)
Search Document