mod timestamp;
mod timevalue;
mod timeinterval;
mod timeset;
mod format;
mod convert;
pub use timevalue::TimeValue;
pub use timestamp::{Timestamp,Timestamped};
pub use timeinterval::*;
pub use timeset::*;
pub use format::{TimeSetFormat,TimePointFormat};
pub use convert::IntoTimeValue;
use crate::iter::TimeConvexIterator;
use crate::TimePoint;
pub trait TimeBounds {
type TimePoint: TimePoint;
fn is_empty(&self) -> bool;
#[inline]
fn is_singleton(&self) -> bool {
!self.is_empty() && self.lower_bound() == self.upper_bound()
}
#[inline]
fn is_bounded(&self) -> bool { self.is_low_bounded() && self.is_up_bounded() }
fn is_low_bounded(&self) -> bool;
fn is_up_bounded(&self) -> bool;
fn lower_bound(&self) -> Self::TimePoint;
fn upper_bound(&self) -> Self::TimePoint;
}
pub trait TimeWindow : TimeBounds {
#[inline]
fn is_all(&self) -> bool {
self.is_convex() && !self.is_low_bounded() && !self.is_up_bounded()
}
#[inline] fn is_convex(&self) -> bool { self.convex_count() <= 1 }
fn convex_count(&self) -> usize;
#[inline] fn convex_envelope(&self) -> TimeInterval<Self::TimePoint> {
TimeInterval { lower: self.lower_bound(), upper: self.upper_bound() }
}
type ConvexIter: TimeConvexIterator<TimePoint=Self::TimePoint>;
fn iter(&self) -> Self::ConvexIter;
}
pub trait TimeConvex : TimeBounds+Sized+Into<TimeInterval<Self::TimePoint>> { }
impl<TW:TimeConvex> TimeWindow for TW {
#[inline] fn is_convex(&self) -> bool { true }
#[inline] fn convex_count(&self) -> usize {
if self.is_empty() { 0 } else { 1 }
}
type ConvexIter = std::option::IntoIter<TimeInterval<Self::TimePoint>>;
#[inline]
fn iter(&self) -> Self::ConvexIter
{
if self.is_empty() {
None.into_iter()
} else {
Some(TimeInterval {
lower:self.lower_bound(),
upper:self.upper_bound()
}).into_iter()
}
}
}
pub trait TimeTruncation : TimeBounds {
fn truncate_before(&mut self, lower: Self::TimePoint) -> bool;
fn truncate_after(&mut self, upper: Self::TimePoint) -> bool;
}