gossamer/date

Types

pub type Date

Values

pub fn date(of date: Date) -> Int

Returns the day of the month (1–31) according to local time.

pub fn day(of date: Date) -> Int

Returns the day of the week (0–6, where 0 is Sunday) according to local time.

pub fn from_string(string: String) -> Result(Date, Nil)

Parses a date string and returns a new Date. Returns an error if the string cannot be parsed as a valid date. Only ISO 8601 format (e.g., “2026-04-09T14:30:00.000Z”) is reliably parsed across all runtimes.

pub fn from_time(time: Int) -> Date

Returns a new Date from the given number of milliseconds since the Unix epoch (January 1, 1970 00:00:00 UTC).

pub fn full_year(of date: Date) -> Int

Returns the four-digit year according to local time.

pub fn hours(of date: Date) -> Int

Returns the hour (0–23) according to local time.

pub fn milliseconds(of date: Date) -> Int

Returns the milliseconds (0–999) according to local time.

pub fn minutes(of date: Date) -> Int

Returns the minutes (0–59) according to local time.

pub fn month(of date: Date) -> Int

Returns the zero-based month (0–11) according to local time.

pub fn new() -> Date

Returns a new Date representing the current date and time.

pub fn now() -> Int

Returns the current timestamp in milliseconds since the Unix epoch.

pub fn parse(string: String) -> Result(Int, Nil)

Parses a date string and returns the corresponding timestamp in milliseconds. Returns an error if the string cannot be parsed. Only ISO 8601 format is reliably parsed across all runtimes.

pub fn seconds(of date: Date) -> Int

Returns the seconds (0–59) according to local time.

pub fn set_date(of date: Date, to day: Int) -> Date

Sets the day of the month according to local time. Mutates the date in-place.

pub fn set_full_year(of date: Date, to year: Int) -> Date

Sets the four-digit year according to local time. Mutates the date in-place.

pub fn set_hours(of date: Date, to hours: Int) -> Date

Sets the hour (0–23) according to local time. Mutates the date in-place.

pub fn set_milliseconds(
  of date: Date,
  to milliseconds: Int,
) -> Date

Sets the milliseconds (0–999) according to local time. Mutates the date in-place.

pub fn set_minutes(of date: Date, to minutes: Int) -> Date

Sets the minutes (0–59) according to local time. Mutates the date in-place.

pub fn set_month(of date: Date, to month: Int) -> Date

Sets the zero-based month (0–11) according to local time. Mutates the date in-place.

pub fn set_seconds(of date: Date, to seconds: Int) -> Date

Sets the seconds (0–59) according to local time. Mutates the date in-place.

pub fn set_time(of date: Date, to time: Int) -> Date

Sets the number of milliseconds since the Unix epoch. Mutates the date in-place.

pub fn set_utc_date(of date: Date, to day: Int) -> Date

Sets the day of the month according to UTC. Mutates the date in-place.

pub fn set_utc_full_year(of date: Date, to year: Int) -> Date

Sets the four-digit year according to UTC. Mutates the date in-place.

pub fn set_utc_hours(of date: Date, to hours: Int) -> Date

Sets the hour (0–23) according to UTC. Mutates the date in-place.

pub fn set_utc_milliseconds(
  of date: Date,
  to milliseconds: Int,
) -> Date

Sets the milliseconds (0–999) according to UTC. Mutates the date in-place.

pub fn set_utc_minutes(of date: Date, to minutes: Int) -> Date

Sets the minutes (0–59) according to UTC. Mutates the date in-place.

pub fn set_utc_month(of date: Date, to month: Int) -> Date

Sets the zero-based month (0–11) according to UTC. Mutates the date in-place.

pub fn set_utc_seconds(of date: Date, to seconds: Int) -> Date

Sets the seconds (0–59) according to UTC. Mutates the date in-place.

pub fn time(of date: Date) -> Int

Returns the number of milliseconds since the Unix epoch.

pub fn timezone_offset(of date: Date) -> Int

Returns the difference, in minutes, between UTC and local time. The value is positive if the local time zone is behind UTC and negative if ahead.

pub fn to_date_string(date: Date) -> String

Returns the date portion as a human-readable string (e.g., “Thu Apr 09 2026”).

pub fn to_iso_string(date: Date) -> String

Returns the date as an ISO 8601 string (e.g., “2026-04-09T14:30:00.000Z”).

pub fn to_json(date: Date) -> String

Returns the date as an ISO 8601 string, suitable for JSON serialization.

pub fn to_locale_date_string(date: Date) -> String

Returns a locale-sensitive string representing the date portion.

pub fn to_locale_string(date: Date) -> String

Returns a locale-sensitive string representing the full date and time.

pub fn to_locale_time_string(date: Date) -> String

Returns a locale-sensitive string representing the time portion.

pub fn to_string(date: Date) -> String

Returns a string representing the date using a runtime-dependent format.

pub fn to_time_string(date: Date) -> String

Returns the time portion as a human-readable string (e.g., “14:30:00 GMT+0000”).

pub fn to_utc_string(date: Date) -> String

Returns the date as a UTC string (e.g., “Thu, 09 Apr 2026 14:30:00 GMT”).

pub fn utc_date(of date: Date) -> Int

Returns the day of the month (1–31) according to UTC.

pub fn utc_day(of date: Date) -> Int

Returns the day of the week (0–6, where 0 is Sunday) according to UTC.

pub fn utc_full_year(of date: Date) -> Int

Returns the four-digit year according to UTC.

pub fn utc_hours(of date: Date) -> Int

Returns the hour (0–23) according to UTC.

pub fn utc_milliseconds(of date: Date) -> Int

Returns the milliseconds (0–999) according to UTC.

pub fn utc_minutes(of date: Date) -> Int

Returns the minutes (0–59) according to UTC.

pub fn utc_month(of date: Date) -> Int

Returns the zero-based month (0–11) according to UTC.

pub fn utc_seconds(of date: Date) -> Int

Returns the seconds (0–59) according to UTC.

Search Document