pg_value/interval

Types

Represents a PostgreSQL interval with months, days, seconds, and microseconds.

pub type Interval {
  Interval(
    months: Int,
    days: Int,
    seconds: Int,
    microseconds: Int,
  )
}

Constructors

  • Interval(months: Int, days: Int, seconds: Int, microseconds: Int)

Values

pub fn add(left: Interval, right: Interval) -> Interval

Returns an Interval with the summed values of each provided Interval

pub fn days(days: Int) -> Interval

Returns an Interval with the provided number of days

pub fn decoder() -> decode.Decoder(Interval)

Returns a decoder that decodes the dynamic value returned by pg_value.decode when decoding an PostgresSQL Interval.

pub fn microseconds(microseconds: Int) -> Interval

Returns an Interval with the provided number of microseconds

pub fn months(months: Int) -> Interval

Returns an Interval with the provided number of months

pub fn seconds(seconds: Int) -> Interval

Returns an Interval with the provided number of seconds

pub fn to_iso8601_string(interval: Interval) -> String

Converts an interval to an ISO8601 formatted string. This function avoids converting the Interval’s units, except for when the number of microseconds includes whole seconds. If more than 1_000_000 microseconds are provided, whole seconds will be derived from the microseconds value. The remaining microseconds will be appended as a decimal in the formatted string.

Interval(months: 14, days: 0, seconds: 86430, microseconds: 0) will be formatted as “P14MT86430S” rather than subdividing months into years or seconds into days and formatting the string as e.g. “P1Y2M1DT30S”.

Interval(months: 0, days: 0, seconds: 10, microseconds: 1_200_000) will be formatted as “PT11.2S”

Search Document