calendar/iso

Types

Format type for date and time string representation

pub type Format {
  Basic
  Extended
}

Constructors

  • Basic
  • Extended

The default calendar implementation, a Gregorian calendar following ISO 8601.

This calendar implements a proleptic Gregorian calendar and is therefore compatible with the calendar used in most countries today.

pub type ParseError {
  InvalidFormat
  InvalidDate
  InvalidTime
  InvalidDuration
}

Constructors

  • InvalidFormat
  • InvalidDate
  • InvalidTime
  • InvalidDuration
pub type ParseResult(t) {
  ParseOk(t)
  ParseError(ParseError)
}

Constructors

Starting day of the week

pub type StartingDay {
  Monday
  Sunday
}

Constructors

  • Monday
  • Sunday

Time unit for precision conversions.

pub type TimeUnit {
  Second
  Millisecond
  Microsecond
  Nanosecond
}

Constructors

  • Second
  • Millisecond
  • Microsecond
  • Nanosecond

Values

pub fn add_day_fraction_to_iso_days(
  iso_days: #(Int, #(Int, Int)),
  add: Int,
  add_ppd: Int,
) -> #(Int, #(Int, Int))

Add a day fraction value to ISO days.

pub fn date_from_iso_days(iso_days: Int) -> #(Int, Int, Int)

Convert days since ISO epoch back to date.

pub fn date_to_iso_days(year: Int, month: Int, day: Int) -> Int

Convert date to days since the ISO epoch.

pub fn date_to_string(
  year: Int,
  month: Int,
  day: Int,
  format: Format,
) -> String

Convert date to string representation

pub fn datetime_to_string(
  year: Int,
  month: Int,
  day: Int,
  hour: Int,
  minute: Int,
  second: Int,
  microsecond: #(Int, Int),
  time_zone: String,
  zone_abbr: String,
  utc_offset: Int,
  std_offset: Int,
  format: Format,
) -> String

Convert datetime to string representation with timezone.

pub fn day_of_era(year: Int, month: Int, day: Int) -> #(Int, Int)

Calculate day of era

pub fn day_of_week(
  year: Int,
  month: Int,
  day: Int,
  starting_day: StartingDay,
) -> Int

Calculate day of week (1-7, where 1 is the starting day)

pub fn day_of_year(year: Int, month: Int, day: Int) -> Int

Calculate day of year (1-366)

pub fn days_in_month(year: Int, month: Int) -> Int

Get the number of days in a month for a given year.

pub fn gregorian_seconds_to_iso_days(
  seconds: Int,
  microsecond: Int,
) -> #(Int, #(Int, Int))

Convert a gregorian seconds value to ISO days representation.

pub fn iso_days_to_beginning_of_day(
  iso_days: #(Int, #(Int, Int)),
) -> #(Int, #(Int, Int))

Get ISO days for the beginning of a day.

pub fn iso_days_to_end_of_day(
  iso_days: #(Int, #(Int, Int)),
) -> #(Int, #(Int, Int))

Get ISO days for the end of a day.

pub fn iso_days_to_unit(
  iso_days: #(Int, #(Int, Int)),
  unit: TimeUnit,
) -> Int

Convert ISO days to a time unit value.

pub fn leap_year(year: Int) -> Bool

Check if a year is a leap year.

pub fn microseconds_to_time(
  total_microseconds: Int,
) -> #(Int, Int, Int, Int)

Convert microseconds since midnight to time components

pub fn months_in_year(year: Int) -> Int

Get the number of months in a year (always 12 for ISO calendar).

pub fn naive_datetime_from_iso_days(
  iso_days: #(Int, #(Int, Int)),
) -> #(Int, Int, Int, Int, Int, Int, #(Int, Int))

Convert ISO days representation back to naive datetime.

pub fn naive_datetime_to_iso_days(
  year: Int,
  month: Int,
  day: Int,
  hour: Int,
  minute: Int,
  second: Int,
  microsecond: #(Int, Int),
) -> #(Int, #(Int, Int))

Convert naive datetime to ISO days representation.

pub fn naive_datetime_to_string(
  year: Int,
  month: Int,
  day: Int,
  hour: Int,
  minute: Int,
  second: Int,
  microsecond: #(Int, Int),
  format: Format,
) -> String

Convert naive datetime to string representation.

pub fn parse_date(
  date_string: String,
) -> ParseResult(#(Int, Int, Int))

Parse an ISO 8601 date string in extended format (YYYY-MM-DD).

pub fn parse_date_with_format(
  date_string: String,
  format: Format,
) -> ParseResult(#(Int, Int, Int))

Parse an ISO 8601 date string with specified format. Extended: YYYY-MM-DD, Basic: YYYYMMDD

pub fn parse_duration(
  duration_string: String,
) -> ParseResult(List(#(String, Int)))

Parse an ISO 8601 duration string.

pub fn parse_naive_datetime(
  datetime_string: String,
) -> ParseResult(#(Int, Int, Int, Int, Int, Int, #(Int, Int)))

Parse an ISO 8601 naive datetime string in extended format (YYYY-MM-DDTHH:MM:SS).

pub fn parse_naive_datetime_with_format(
  datetime_string: String,
  format: Format,
) -> ParseResult(#(Int, Int, Int, Int, Int, Int, #(Int, Int)))

Parse an ISO 8601 naive datetime string with specified format. Extended: YYYY-MM-DDTHH:MM:SS, Basic: YYYYMMDDTHHMMSS Also accepts space separator.

pub fn parse_time(
  time_string: String,
) -> ParseResult(#(Int, Int, Int, #(Int, Int)))

Parse an ISO 8601 time string in extended format (HH:MM:SS or HH:MM:SS.ffffff).

pub fn parse_time_with_format(
  time_string: String,
  format: Format,
) -> ParseResult(#(Int, Int, Int, #(Int, Int)))

Parse an ISO 8601 time string with specified format. Extended: HH:MM:SS[.ffffff], Basic: HHMMSS[.ffffff] Also accepts a leading ‘T’ prefix which is stripped.

pub fn parse_utc_datetime(
  datetime_string: String,
) -> ParseResult(
  #(#(Int, Int, Int, Int, Int, Int, #(Int, Int)), Int),
)

Parse an ISO 8601 UTC datetime string with offset. Returns the datetime components and the UTC offset in seconds.

pub fn parse_utc_datetime_with_format(
  datetime_string: String,
  format: Format,
) -> ParseResult(
  #(#(Int, Int, Int, Int, Int, Int, #(Int, Int)), Int),
)

Parse an ISO 8601 UTC datetime string with specified format.

pub fn quarter_of_year(year: Int, month: Int, day: Int) -> Int

Calculate quarter of year (1-4).

pub fn shift_date(
  year: Int,
  month: Int,
  day: Int,
  month_shift: Int,
  day_shift: Int,
) -> #(Int, Int, Int)

Shift a date by a duration. Duration is given as #(months, days) where months includes year*12.

pub fn shift_naive_datetime(
  year: Int,
  month: Int,
  day: Int,
  hour: Int,
  minute: Int,
  second: Int,
  microsecond: #(Int, Int),
  month_shift: Int,
  day_shift: Int,
  second_shift: Int,
  microsecond_shift: Int,
) -> #(Int, Int, Int, Int, Int, Int, #(Int, Int))

Shift a naive datetime by duration components.

pub fn shift_time(
  hour: Int,
  minute: Int,
  second: Int,
  microsecond: #(Int, Int),
  second_shift: Int,
  microsecond_shift: Int,
) -> #(Int, Int, Int, #(Int, Int))

Shift time by duration components.

pub fn time_from_day_fraction(
  day_fraction: #(Int, Int),
) -> #(Int, Int, Int, #(Int, Int))

Convert day fraction back to time components.

pub fn time_to_day_fraction(
  hour: Int,
  minute: Int,
  second: Int,
  microsecond: #(Int, Int),
) -> #(Int, Int)

Convert time to day fraction representation. Day fraction is {microseconds_in_day, parts_per_day}.

pub fn time_to_microseconds(
  hour: Int,
  minute: Int,
  second: Int,
  microsecond: Int,
) -> Int

Convert time to microseconds since midnight

pub fn time_to_string(
  hour: Int,
  minute: Int,
  second: Int,
  microsecond: Int,
  format: Format,
) -> String

Convert time to string representation

pub fn time_unit_to_precision(unit: TimeUnit) -> Int

Get the precision for a time unit.

pub fn valid_date(year: Int, month: Int, day: Int) -> Bool

Check if a date is valid

pub fn valid_time(
  hour: Int,
  minute: Int,
  second: Int,
  microsecond: Int,
) -> Bool

Check if a time is valid

pub fn year_of_era(year: Int) -> #(Int, Int)

Calculate year of era from a year.

pub fn year_of_era_from_date(
  year: Int,
  month: Int,
  day: Int,
) -> #(Int, Int)

Calculate year of era from a date.

Search Document