+ boost::optional<TimePeriod<T> > overlap (TimePeriod<T> const & other) {
+ T const max_from = std::max (from, other.from);
+ T const min_to = std::min (to, other.to);
+
+ if (max_from >= min_to) {
+ return boost::optional<TimePeriod<T> > ();
+ }
+
+ return TimePeriod<T> (max_from, min_to);
+ }
+
+ bool contains (T const & other) const {
+ return (from <= other && other < to);
+ }
+
+ bool operator< (TimePeriod<T> const & o) const {
+ if (from != o.from) {
+ return from < o.from;
+ }
+ return to < o.to;
+ }
+
+ bool operator== (TimePeriod<T> const & other) const {
+ return from == other.from && to == other.to;
+ }
+
+ bool operator!= (TimePeriod<T> const & other) const {
+ return !(*this == other);
+ }