Struct Interval
pub struct Interval<Tz>where
Tz: TimeZone,{
start: DateTime<Tz>,
end: DateTime<Tz>,
}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,
impl<Tz> Interval<Tz>where
Tz: TimeZone,
Sourcepub fn new(start: DateTime<Tz>, end: DateTime<Tz>) -> Option<Interval<Tz>>
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.
Sourcepub 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.
Sourcepub fn contains(&self, dt: DateTime<Tz>) -> bool
pub fn contains(&self, dt: DateTime<Tz>) -> bool
Returns true if a datetime is within the interval.
Sourcepub 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.
Sourcepub fn checked_add_days(self, days: Days) -> Option<Interval<Tz>>
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.