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
impl Interval
pub const CENTURY_PER_MILLENNIUM: u16 = 10u16
pub const DECADE_PER_CENTURY: u16 = 10u16
pub const YEAR_PER_DECADE: u16 = 10u16
pub const MONTH_PER_YEAR: u16 = 12u16
pub const DAY_PER_MONTH: u16 = 30u16
pub const HOUR_PER_DAY: u16 = 24u16
pub const MINUTE_PER_HOUR: u16 = 60u16
pub const SECOND_PER_MINUTE: u16 = 60u16
pub const MILLISECOND_PER_SECOND: u16 = 1_000u16
pub const MICROSECOND_PER_MILLISECOND: u16 = 1_000u16
pub const NANOSECOND_PER_MICROSECOND: u16 = 1_000u16
pub const EPOCH_DAYS_PER_YEAR: f64 = 365.25f64
sourcepub const fn new(months: i32, days: i32, micros: i64) -> Interval
pub const fn new(months: i32, days: i32, micros: i64) -> Interval
Constructs a new Interval
with the specified units of time.
sourcepub fn from_duration(duration: &Duration) -> Result<Interval, Error>
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.
pub fn checked_add(&self, other: &Self) -> Option<Self>
pub fn checked_mul(&self, other: f64) -> Option<Self>
pub fn checked_div(&self, other: f64) -> Option<Self>
fn checked_op<F1>(&self, other: f64, op: F1) -> Option<Self>
sourcepub fn millennia(&self) -> i32
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
.
sourcepub fn centuries(&self) -> i32
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
.
sourcepub fn decades(&self) -> i32
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
.
sourcepub fn years(&self) -> i32
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
.
sourcepub fn quarters(&self) -> i32
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
.
sourcepub fn months(&self) -> i32
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
.
sourcepub fn days(&self) -> i64
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
.
sourcepub fn hours(&self) -> i64
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
.
sourcepub fn minutes(&self) -> i64
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
.
sourcepub fn seconds<T>(&self) -> Twhere
T: DecimalLike,
pub fn seconds<T>(&self) -> Twhere
T: DecimalLike,
Computes the second part of the interval.
The second part is the number of fractional seconds in the interval, modulo 60.0.
sourcepub fn milliseconds<T>(&self) -> Twhere
T: DecimalLike,
pub fn milliseconds<T>(&self) -> Twhere
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.
sourcepub fn microseconds<T>(&self) -> Twhere
T: DecimalLike,
pub fn microseconds<T>(&self) -> Twhere
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.
sourcepub fn nanoseconds(&self) -> i32
pub fn nanoseconds(&self) -> i32
Computes the nanosecond part of the interval.
sourcepub fn as_epoch_seconds<T>(&self) -> Twhere
T: DecimalLike,
pub fn as_epoch_seconds<T>(&self) -> Twhere
T: DecimalLike,
Computes the total number of epoch seconds in the interval. When extracting an epoch, PostgreSQL considers a year 365.25 days.
sourcepub fn as_microseconds(&self) -> i128
pub fn as_microseconds(&self) -> i128
Computes the total number of microseconds in the interval.
sourcepub fn as_milliseconds(&self) -> i128
pub fn as_milliseconds(&self) -> i128
Computes the total number of milliseconds in the interval. Discards fractional milliseconds!
sourcepub fn duration_as_chrono(&self) -> Duration
pub fn duration_as_chrono(&self) -> Duration
Converts this Interval
’s duration into chrono::Duration
.
pub fn duration(&self) -> Result<Duration, Error>
sourcepub fn truncate_high_fields(&mut self, f: DateTimeField)
pub fn truncate_high_fields(&mut self, f: DateTimeField)
Truncate the “head” of the interval, removing all time units greater than f
.
sourcepub fn truncate_low_fields(
&mut self,
f: DateTimeField,
fsec_max_precision: Option<u64>,
round_behavior: RoundBehavior,
) -> Result<(), Error>
pub fn truncate_low_fields( &mut self, f: DateTimeField, fsec_max_precision: Option<u64>, round_behavior: RoundBehavior, ) -> Result<(), Error>
sourcepub fn as_time_interval(&self) -> Self
pub fn as_time_interval(&self) -> Self
Returns a new Interval with only the time component
sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns true if combining all fields results in a negative number, false otherwise
sourcepub fn convert_date_time_unit<T>(
source: DateTimeField,
dest: DateTimeField,
val: T,
) -> Option<T>
pub fn convert_date_time_unit<T>( source: DateTimeField, dest: DateTimeField, val: T, ) -> Option<T>
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.
fn convert_date_time_unit_increasing<T>( source: DateTimeField, dest: DateTimeField, val: T, ) -> Option<T>
fn convert_date_time_unit_decreasing<T>( source: DateTimeField, dest: DateTimeField, val: T, ) -> Option<T>
sourcepub fn justify_days(&self) -> Result<Self, Error>
pub fn justify_days(&self) -> Result<Self, Error>
Adjust interval so ‘days’ contains less than 30 days, adding the excess to ‘months’.
fn justify_days_inner(months: i32, days: i32) -> Result<(i32, i32), Error>
sourcepub fn justify_hours(&self) -> Result<Self, Error>
pub fn justify_hours(&self) -> Result<Self, Error>
Adjust interval so ‘micros’ contains less than a whole day, adding the excess to ‘days’.
fn justify_hours_inner(days: i32, micros: i64) -> Result<(i32, i64), Error>
sourcepub fn justify_interval(&self) -> Result<Self, Error>
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
impl Arbitrary for Interval
§type Strategy = BoxedStrategy<Interval>
type Strategy = BoxedStrategy<Interval>
Strategy
used to generate values of type Self
.§type Parameters = ()
type Parameters = ()
arbitrary_with
accepts for configuration
of the generated Strategy
. Parameters must implement Default
.source§fn arbitrary_with(_: Self::Parameters) -> Self::Strategy
fn arbitrary_with(_: Self::Parameters) -> Self::Strategy
source§impl<'a> AsColumnType for Interval
impl<'a> AsColumnType for Interval
source§fn as_column_type() -> ColumnType
fn as_column_type() -> ColumnType
source§impl CheckedNeg for Interval
impl CheckedNeg for Interval
source§fn checked_neg(&self) -> Option<Self>
fn checked_neg(&self) -> Option<Self>
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 moresource§impl ColumnarStatsBuilder<Interval> for IntervalStatsBuilder
impl ColumnarStatsBuilder<Interval> for IntervalStatsBuilder
§type ArrowColumn = FixedSizeBinaryArray
type ArrowColumn = FixedSizeBinaryArray
arrow
column these statistics can be derived from.§type FinishedStats = BytesStats
type FinishedStats = BytesStats
source§fn from_column(col: &Self::ArrowColumn) -> Selfwhere
Self: Sized,
fn from_column(col: &Self::ArrowColumn) -> Selfwhere
Self: Sized,
source§fn finish(self) -> Self::FinishedStatswhere
Self::FinishedStats: Sized,
fn finish(self) -> Self::FinishedStatswhere
Self::FinishedStats: Sized,
source§impl<'a, E> DatumType<'a, E> for Interval
impl<'a, E> DatumType<'a, E> for Interval
source§impl<'de> Deserialize<'de> for Interval
impl<'de> Deserialize<'de> for Interval
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for Interval
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§impl FixedSizeCodec<Interval> for PackedInterval
impl FixedSizeCodec<Interval> for PackedInterval
source§fn from_bytes(slice: &[u8]) -> Result<Self, String>
fn from_bytes(slice: &[u8]) -> Result<Self, String>
self
from a slice. Read moresource§fn from_value(value: Interval) -> Self
fn from_value(value: Interval) -> Self
T
into this format.source§fn into_value(self) -> Interval
fn into_value(self) -> Interval
T
from this format.source§impl Ord for Interval
impl Ord for Interval
source§impl PartialOrd for Interval
impl PartialOrd for Interval
source§impl RustType<ProtoInterval> for Interval
impl RustType<ProtoInterval> for Interval
source§fn into_proto(&self) -> ProtoInterval
fn into_proto(&self) -> ProtoInterval
Self
into a Proto
value.source§fn from_proto(proto: ProtoInterval) -> Result<Self, TryFromProtoError>
fn from_proto(proto: ProtoInterval) -> Result<Self, TryFromProtoError>
source§fn into_proto_owned(self) -> Proto
fn into_proto_owned(self) -> Proto
Self::into_proto
that types can
optionally implement, otherwise, the default implementation
delegates to Self::into_proto
.impl Copy for Interval
impl Eq for Interval
impl StructuralPartialEq for Interval
Auto Trait Implementations§
impl Freeze for Interval
impl RefUnwindSafe for Interval
impl Send for Interval
impl Sync for Interval
impl Unpin for Interval
impl UnwindSafe for Interval
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
source§impl<T, U> OverrideFrom<Option<&T>> for Uwhere
U: OverrideFrom<T>,
impl<T, U> OverrideFrom<Option<&T>> for Uwhere
U: OverrideFrom<T>,
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> PreferredContainer for T
impl<T> PreferredContainer for T
source§impl<T> ProgressEventTimestamp for T
impl<T> ProgressEventTimestamp for T
source§impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
source§fn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
RustType::from_proto
.source§fn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
RustType::into_proto
.source§impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
source§fn plus_equals(&mut self, rhs: &&'a S)
fn plus_equals(&mut self, rhs: &&'a S)
std::ops::AddAssign
, for types that do not implement AddAssign
.