1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::cmp::Ordering;
use crate::{TimeBounds, TimeInterval, TimePoint, TimeSet, TimeWindow};


impl<T:TimePoint,TW> PartialEq<TW> for TimeInterval<T>
    where
        TW: TimeWindow<TimePoint=T>
{
    #[inline]
    fn eq(&self, other: &TW) -> bool {
        other.is_convex()
            && self.lower == other.lower_bound()
            && self.upper == other.upper_bound()
    }
}

impl<T:TimePoint,TW> PartialEq<TW> for TimeSet<T>
    where
        TW: TimeWindow<TimePoint=T>
{
    #[inline]
    fn eq(&self, other: &TW) -> bool {
        self.iter().eq(other.iter())
    }
}

macro_rules! timepartialcmp {
    ($time:ident) => {
        impl<T:TimePoint,TW> PartialOrd<TW> for $time<T>
            where
                TW: TimeWindow<TimePoint=T>
        {
            #[inline]
            fn partial_cmp(&self, other: &TW) -> Option<Ordering>
            {
                if self.lt(other){
                    Some(Ordering::Less)
                } else if self.gt(other) {
                    Some(Ordering::Greater)
                } else if self.eq(other) {
                    Some(Ordering::Equal)
                } else {
                    None
                }
            }

            #[inline]
            fn lt(&self, other: &TW) -> bool {
                self.upper_bound() < other.lower_bound()
            }

            #[inline]
            fn le(&self, other: &TW) -> bool {
                self.lt(other) || self.eq(other)
            }

            #[inline]
            fn gt(&self, other: &TW) -> bool {
                self.lower_bound() > other.upper_bound()
            }

            #[inline]
            fn ge(&self, other: &TW) -> bool {
                self.gt(other) || self.eq(other)
            }
        }
    }
}

timepartialcmp!(TimeInterval);
timepartialcmp!(TimeSet);