gossamer/time_extra

Extras for gleam/time/timestamp — RFC 7231 HTTP date-header strings and day-of-week, neither of which gleam_time exposes itself.

Types

A day of the week. Mirrors the shape of gleam/time/calendar.Month.

pub type Weekday {
  Monday
  Tuesday
  Wednesday
  Thursday
  Friday
  Saturday
  Sunday
}

Constructors

  • Monday
  • Tuesday
  • Wednesday
  • Thursday
  • Friday
  • Saturday
  • Sunday

Values

pub fn day_of_week(
  timestamp: timestamp.Timestamp,
  offset: duration.Duration,
) -> Weekday

Returns the day of the week for the given offset. Pass gleam/time/calendar.utc_offset for UTC or gleam/time/calendar.local_offset() for the host’s local timezone. Covers the full Timestamp range. Equivalent to JavaScript’s Date.prototype.getDay.

pub fn to_utc_string(timestamp: timestamp.Timestamp) -> String

Returns the timestamp as an RFC 7231 string (e.g., "Thu, 01 Jan 1970 00:00:00 GMT"). This is the format used by HTTP Date, Last-Modified, and Expires headers. Covers the full Timestamp range. Equivalent to JavaScript’s Date.prototype.toUTCString.

pub fn weekday_from_int(weekday: Int) -> Result(Weekday, Nil)

Returns the weekday for a given number, where Monday is 1 and Sunday is 7, following ISO 8601.

Examples

weekday_from_int(1)
// -> Ok(Monday)
pub fn weekday_to_int(weekday: Weekday) -> Int

Returns the number for the weekday, where Monday is 1 and Sunday is 7, following ISO 8601.

Examples

weekday_to_int(Monday)
// -> 1
pub fn weekday_to_string(weekday: Weekday) -> String

Returns the English name for the weekday.

Examples

weekday_to_string(Monday)
// -> "Monday"
Search Document