Struct mz_repr::adt::interval::Interval

source ·
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§

source§

impl Interval

source

pub const CENTURY_PER_MILLENNIUM: u16 = 10u16

source

pub const DECADE_PER_CENTURY: u16 = 10u16

source

pub const YEAR_PER_DECADE: u16 = 10u16

source

pub const MONTH_PER_YEAR: u16 = 12u16

source

pub const DAY_PER_MONTH: u16 = 30u16

source

pub const HOUR_PER_DAY: u16 = 24u16

source

pub const MINUTE_PER_HOUR: u16 = 60u16

source

pub const SECOND_PER_MINUTE: u16 = 60u16

source

pub const MILLISECOND_PER_SECOND: u16 = 1_000u16

source

pub const MICROSECOND_PER_MILLISECOND: u16 = 1_000u16

source

pub const NANOSECOND_PER_MICROSECOND: u16 = 1_000u16

source

pub const EPOCH_DAYS_PER_YEAR: f64 = 365.25f64

source

pub const fn new(months: i32, days: i32, micros: i64) -> Interval

Constructs a new Interval with the specified units of time.

source

pub fn from_duration(duration: &Duration) -> Result<Interval, Error>

Converts a Duration to an Interval. The resulting Interval will only have microseconds. Errors if

  • the number of microseconds doesn’t fit in i64, or
  • the Duration involves fractional microseconds.
source

pub fn checked_add(&self, other: &Self) -> Option<Self>

source

pub fn checked_mul(&self, other: f64) -> Option<Self>

source

pub fn checked_div(&self, other: f64) -> Option<Self>

source

fn checked_op<F1>(&self, other: f64, op: F1) -> Option<Self>
where F1: Fn(f64, f64) -> f64,

source

pub fn millennia(&self) -> i32

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.

source

pub fn centuries(&self) -> i32

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.

source

pub fn decades(&self) -> i32

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.

source

pub fn years(&self) -> i32

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.

source

pub fn quarters(&self) -> i32

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.

source

pub fn months(&self) -> i32

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.

source

pub fn days(&self) -> i64

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.

source

pub fn hours(&self) -> i64

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.

source

pub fn minutes(&self) -> i64

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.

source

pub fn seconds<T>(&self) -> T
where T: DecimalLike,

Computes the second part of the interval.

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

source

pub fn milliseconds<T>(&self) -> T
where T: DecimalLike,

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.

source

pub fn microseconds<T>(&self) -> T
where T: DecimalLike,

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.

source

pub fn nanoseconds(&self) -> i32

Computes the nanosecond part of the interval.

source

pub fn as_epoch_seconds<T>(&self) -> T
where T: DecimalLike,

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

source

pub fn as_microseconds(&self) -> i128

Computes the total number of microseconds in the interval.

source

pub fn as_milliseconds(&self) -> i128

Computes the total number of milliseconds in the interval. Discards fractional milliseconds!

source

pub fn duration_as_chrono(&self) -> Duration

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

source

pub fn duration(&self) -> Result<Duration, Error>

source

pub fn truncate_high_fields(&mut self, f: DateTimeField)

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

source

pub fn truncate_low_fields( &mut self, f: DateTimeField, fsec_max_precision: Option<u64>, round_behavior: RoundBehavior, ) -> Result<(), Error>

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).
source

pub fn as_time_interval(&self) -> Self

Returns a new Interval with only the time component

source

pub fn is_negative(&self) -> bool

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

source

pub fn convert_date_time_unit<T>( source: DateTimeField, dest: DateTimeField, val: T, ) -> Option<T>
where T: From<u16> + CheckedMul + DivAssign,

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.

source

fn convert_date_time_unit_increasing<T>( source: DateTimeField, dest: DateTimeField, val: T, ) -> Option<T>
where T: From<u16> + DivAssign,

source

fn convert_date_time_unit_decreasing<T>( source: DateTimeField, dest: DateTimeField, val: T, ) -> Option<T>
where T: From<u16> + CheckedMul,

source

pub fn justify_days(&self) -> Result<Self, Error>

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

source

fn justify_days_inner(months: i32, days: i32) -> Result<(i32, i32), Error>

source

pub fn justify_hours(&self) -> Result<Self, Error>

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

source

fn justify_hours_inner(days: i32, micros: i64) -> Result<(i32, i64), Error>

source

pub fn justify_interval(&self) -> Result<Self, Error>

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§

source§

impl Arbitrary for Interval

§

type Strategy = BoxedStrategy<Interval>

The type of Strategy used to generate values of type Self.
§

type Parameters = ()

The type of parameters that arbitrary_with accepts for configuration of the generated Strategy. Parameters must implement Default.
source§

fn arbitrary_with(_: Self::Parameters) -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). The strategy is passed the arguments given in args. Read more
source§

fn arbitrary() -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). Read more
source§

impl<'a> AsColumnType for Interval

source§

fn as_column_type() -> ColumnType

The SQL column type of this Rust type
source§

impl CheckedNeg for Interval

source§

fn checked_neg(&self) -> Option<Self>

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
source§

impl Clone for Interval

source§

fn clone(&self) -> Interval

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, E> DatumType<'a, E> for Interval

source§

fn nullable() -> bool

Whether this Rust type can represent NULL values
source§

fn fallible() -> bool

Whether this Rust type can represent errors
source§

fn try_from_result( res: Result<Datum<'a>, E>, ) -> Result<Self, Result<Datum<'a>, E>>

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.
source§

fn into_result(self, _temp_storage: &'a RowArena) -> Result<Datum<'a>, E>

Convert this Rust type into a Result containing a Datum, or an error
source§

impl Debug for Interval

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Interval

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Interval

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Interval

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
source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FixedSizeCodec<Interval> for PackedInterval

source§

const SIZE: usize = 16usize

Number of bytes the encoded format requires.
source§

fn as_bytes(&self) -> &[u8]

Returns the encoded bytes as a slice.
source§

fn from_bytes(slice: &[u8]) -> Result<Self, String>

Create an instance of self from a slice. Read more
source§

fn from_value(value: Interval) -> Self

Encode a type of T into this format.
source§

fn into_value(self) -> Interval

Decode an instance of T from this format.
source§

impl<'a> From<Interval> for Datum<'a>

source§

fn from(other: Interval) -> Datum<'a>

Converts to this type from the input type.
source§

impl FromStr for Interval

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for Interval

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Interval

source§

fn cmp(&self, other: &Interval) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Interval

source§

fn eq(&self, other: &Interval) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Interval

source§

fn partial_cmp(&self, other: &Interval) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl RustType<ProtoInterval> for Interval

source§

fn into_proto(&self) -> ProtoInterval

Convert a Self into a Proto value.
source§

fn from_proto(proto: ProtoInterval) -> Result<Self, TryFromProtoError>

Consume and convert a Proto back into a Self value. Read more
source§

fn into_proto_owned(self) -> Proto

A zero clone version of Self::into_proto that types can optionally implement, otherwise, the default implementation delegates to Self::into_proto.
source§

impl Serialize for Interval

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<Datum<'_>> for Interval

§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_from(from: Datum<'_>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for Interval

source§

impl Eq for Interval

source§

impl StructuralPartialEq for Interval

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

fn cast_into(self) -> U

Performs the cast.
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<T> CopyAs<T> for T

source§

fn copy_as(self) -> T

source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromRef<T> for T
where T: Clone,

source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> FutureExt for T

source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
source§

impl<T> Hashable for T
where T: Hash,

§

type Output = u64

The type of the output value.
source§

fn hashed(&self) -> u64

A well-distributed integer derived from the data.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T, U> OverrideFrom<Option<&T>> for U
where U: OverrideFrom<T>,

source§

fn override_from(self, layer: &Option<&T>) -> U

Override the configuration represented by Self with values from the given layer.
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> PreferredContainer for T
where T: Ord + Clone + 'static,

§

type Container = Vec<T>

The preferred container for the type.
source§

impl<T> ProgressEventTimestamp for T
where T: Data + Debug + Any,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Upcasts this ProgressEventTimestamp to Any. Read more
source§

fn type_name(&self) -> &'static str

Returns the name of the concrete type of this object. Read more
source§

impl<P, R> ProtoType<R> for P
where R: RustType<P>,

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<'a, S, T> Semigroup<&'a S> for T
where T: Semigroup<S>,

source§

fn plus_equals(&mut self, rhs: &&'a S)

The method of std::ops::AddAssign, for types that do not implement AddAssign.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

source§

impl<T> Data for T
where T: Clone + 'static,

source§

impl<T> Data for T
where T: Data + Ord + Debug,

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> ExchangeData for T
where T: Data + Data,

source§

impl<T> ExchangeData for T
where T: ExchangeData + Ord + Debug,

source§

impl<T> Index for T
where T: Copy + Serialize + for<'a> Deserialize<'a>,

source§

impl<T> Sequence for T
where T: Eq + Hash,