Struct Interval
pub struct Interval<Tz: TimeZone> {
start: DateTime<Tz>,
end: DateTime<Tz>,
}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§
§impl<Tz: TimeZone> Interval<Tz>
impl<Tz: TimeZone> Interval<Tz>
pub fn new(start: DateTime<Tz>, end: DateTime<Tz>) -> Option<Self>
pub fn new(start: DateTime<Tz>, end: DateTime<Tz>) -> Option<Self>
Creates a new interval from start and end datetimes.
Returns None if the end is before the start.
pub const fn time_delta(&self) -> TimeDelta
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.
pub fn order_datetime(&self, dt: DateTime<Tz>) -> Ordering
pub fn order_datetime(&self, dt: DateTime<Tz>) -> Ordering
Compares a datetime with the interval.
Returns:
Lessif the datetime is before the start of the interval,Greaterif the datetime is after the end of the interval,Equalif the datetime is within the interval.
pub fn checked_add_days(self, days: Days) -> Option<Self>
pub fn checked_add_days(self, days: Days) -> Option<Self>
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§
§impl<'de> Deserialize<'de> for Interval<FixedOffset>
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Interval<FixedOffset>
serde only.