Expand description
Closed datetime ranges: containment, overlap, intersection and union. Closed datetime ranges.
A DateTimeRange is the set of
instants from start to end, both bounds included, matching
DateTime::is_within_range.
Bounds compare by absolute instant, so a range may mix offsets.
§Examples
use dtt::datetime::DateTime;
use dtt::range::DateTimeRange;
let morning = DateTimeRange::new(
DateTime::parse("2024-01-15T09:00:00Z")?,
DateTime::parse("2024-01-15T12:00:00Z")?,
)?;
let lunch = DateTimeRange::new(
DateTime::parse("2024-01-15T12:00:00Z")?,
DateTime::parse("2024-01-15T13:00:00Z")?,
)?;
assert!(morning.intersects(&lunch)); // they share 12:00:00
let day = morning.union(&lunch).ok_or(dtt::error::DateTimeError::InvalidRange)?;
assert_eq!(day.duration(), time::Duration::hours(4));Structs§
- Date
Time Range - A closed interval of instants,
start <= end, bounds inclusive.