pub struct Interval {
    pub months: i32,
    pub days: i32,
    pub micros: i64,
}
Expand description

An interval of time meant to express SQL intervals.

Obtained by parsing an INTERVAL '<value>' <unit> [TO <precision>].

Fields

months: i32

A possibly negative number of months for field types like YEAR

days: i32

A possibly negative number of days.

Irrespective of values, days will not be carried over into months.

micros: i64

A timespan represented in microseconds.

Irrespective of values, micros will not be carried over into days or months.

Implementations

Constructs a new Interval with the specified units of time.

Computes the millennium part of the interval.

The millennium part is the number of whole millennia in the interval. For example, this function returns 3 for the interval 3400 years.

Computes the century part of the interval.

The century part is the number of whole centuries in the interval. For example, this function returns 3 for the interval 340 years.

Computes the decade part of the interval.

The decade part is the number of whole decades in the interval. For example, this function returns 3 for the interval 34 years.

Computes the year part of the interval.

The year part is the number of whole years in the interval. For example, this function returns 3 for the interval 3 years 4 months.

Computes the quarter part of the interval.

The quarter part is obtained from taking the number of whole months modulo 12, and assigning quarter #1 for months 0-2, #2 for 3-5, #3 for 6-8 and #4 for 9-11. For example, this function returns 4 for the interval 11 months.

Computes the month part of the interval.

The month part is the number of whole months in the interval, modulo 12. For example, this function returns 4 for the interval 3 years 4 months.

Computes the day part of the interval.

The day part is the number of whole days in the interval. For example, this function returns 5 for the interval 5 days 4 hours 3 minutes 2.1 seconds.

Computes the hour part of the interval.

The hour part is the number of whole hours in the interval, modulo 24. For example, this function returns 4 for the interval 5 days 4 hours 3 minutes 2.1 seconds.

Computes the minute part of the interval.

The minute part is the number of whole minutes in the interval, modulo 60. For example, this function returns 3 for the interval 5 days 4 hours 3 minutes 2.1 seconds.

Computes the second part of the interval.

The second part is the number of fractional seconds in the interval, modulo 60.0.

Computes the second part of the interval displayed in milliseconds.

The second part is the number of fractional seconds in the interval, modulo 60.0.

Computes the second part of the interval displayed in microseconds.

The second part is the number of fractional seconds in the interval, modulo 60.0.

Computes the nanosecond part of the interval.

Computes the total number of epoch seconds in the interval. When extracting an epoch, PostgreSQL considers a year 365.25 days.

Computes the total number of microseconds in the interval.

Converts this Interval’s duration into chrono::Duration.

Truncate the “head” of the interval, removing all time units greater than f.

Truncate the “tail” of the interval, removing all time units less than f.

Arguments
  • f: Round the interval down to the specified time unit.
  • fsec_max_precision: If Some(x), keep only x places of microsecond precision. Must be (0,6).
Errors
  • If fsec_max_precision is not None or within (0,6).

Returns a new Interval with only the time component

Returns true if combining all fields results in a negative number, false otherwise

Convert val from source unit to dest unit. Does not maintain fractional values. Returns None if the result overflows/underflows.

WARNING: Due to the fact that Intervals consider months to have 30 days, you may get unexpected and incorrect results when trying to convert from a non-year type to a year type and vice versa. For example from years to days.

Adjust interval so ‘days’ contains less than 30 days, adding the excess to ‘months’.

Adjust interval so ‘micros’ contains less than a whole day, adding the excess to ‘days’.

Adjust interval so ‘days’ contains less than 30 days, adding the excess to ‘months’. Adjust interval so ‘micros’ contains less than a whole day, adding the excess to ‘days’. Also, the sign bit on all three fields is made equal, so either all three fields are negative or all are positive.

Trait Implementations

The SQL column type of this Rust type
Negates a number, returning None for results that can’t be represented, like signed MIN values that can’t be positive, or non-zero unsigned values that can’t be negative. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Whether this Rust type can represent NULL values
Try to convert a Result whose Ok variant is a Datum into this native Rust type (Self). If it fails the error variant will contain the original result. Read more
Convert this Rust type into a Result containing a Datum, or an error
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more

Format an interval in a human form

Example outputs:

  • 1 year 2 months 5 days 03:04:00
  • -1 year +5 days +18:59:29.3
  • 00:00:00
Formats the value using the given formatter. Read more
Converts to this type from the input type.
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Convert a Self into a Proto value.
Consume and convert a Proto back into a Self value. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Formats an object with the “alternative” format ({:#}) and returns it.
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Attaches the current Context to this type, returning a WithContext wrapper. Read more
The type of the output value.
A well-distributed integer derived from the data.
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Wrap the input message T in a tonic::Request
Upcasts this ProgressEventTimestamp to Any. Read more
Returns the name of the concrete type of this object. Read more
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more