Interval

Struct Interval 

pub struct Interval<Tz>
where Tz: TimeZone,
{ start: DateTime<Tz>, end: DateTime<Tz>, }
Available on crate feature time only.
Expand description

Half-open time interval.

The interval is defined two DateTimes [start, end), where start is inclusive and end is exclusive.

The interval is modelled after the ISO 8601 time interval format, but it only supports the fully qualified start/end format.

§Format

The string representation is in the format <start>/<end>, where both <start> and <end> are full RFC 3339 date-time strings. No other ISO 8601 formats are supported.

If the serde feature is enabled, the type can be serialized and deserialized as a string in this format.

Fields§

§start: DateTime<Tz>§end: DateTime<Tz>

Implementations§

Source§

impl<Tz> Interval<Tz>
where Tz: TimeZone,

Source

pub fn new(start: DateTime<Tz>, end: DateTime<Tz>) -> Option<Interval<Tz>>

Creates a new interval from start and end datetimes.

Returns None if the end is before the start.

Source

pub const fn start(&self) -> &DateTime<Tz>

Returns the start of the interval.

Source

pub const fn end(&self) -> &DateTime<Tz>

Returns the end of the interval.

Source

pub const fn time_delta(&self) -> TimeDelta

Returns the duration of the interval as a TimeDelta.

The return value is always non-negative since start <= end.

Source

pub const fn duration(&self) -> Duration

Returns the duration of the interval as a Duration.

Source

pub fn contains(&self, dt: DateTime<Tz>) -> bool

Returns true if a datetime is within the interval.

Source

pub fn order_datetime(&self, dt: DateTime<Tz>) -> Ordering

Compares a datetime with the interval.

Returns:

  • Less if the datetime is before the start of the interval,
  • Greater if the datetime is after the end of the interval,
  • Equal if the datetime is within the interval.
Source

pub fn checked_add_days(self, days: Days) -> Option<Interval<Tz>>

Returns a new interval that is shifted by the given number of days.

Returns None if either start or end returns None when adding the days. See DateTime::checked_add_days for the conditions.

Trait Implementations§

Source§

impl<Tz> Clone for Interval<Tz>
where Tz: Clone + TimeZone,

Source§

fn clone(&self) -> Interval<Tz>

Returns a duplicate 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<Tz> Debug for Interval<Tz>
where Tz: Debug + TimeZone,

Source§

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

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

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

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Interval<FixedOffset>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

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

impl<Tz> Display for Interval<Tz>
where Tz: TimeZone, <Tz as TimeZone>::Offset: Display,

Source§

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

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

impl FromStr for Interval<FixedOffset>

Source§

type Err = ParseError

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

fn from_str( s: &str, ) -> Result<Interval<FixedOffset>, <Interval<FixedOffset> as FromStr>::Err>

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

impl<Tz> Serialize for Interval<Tz>
where Tz: TimeZone, <Tz as TimeZone>::Offset: Display,

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<Tz> Freeze for Interval<Tz>
where <Tz as TimeZone>::Offset: Freeze,

§

impl<Tz> RefUnwindSafe for Interval<Tz>
where <Tz as TimeZone>::Offset: RefUnwindSafe,

§

impl<Tz> Send for Interval<Tz>
where <Tz as TimeZone>::Offset: Send,

§

impl<Tz> Sync for Interval<Tz>
where <Tz as TimeZone>::Offset: Sync,

§

impl<Tz> Unpin for Interval<Tz>
where <Tz as TimeZone>::Offset: Unpin,

§

impl<Tz> UnwindSafe for Interval<Tz>
where <Tz as TimeZone>::Offset: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> ToOwned for T
where T: Clone,

Source§

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§

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>,

Source§

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>,

Source§

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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