00001 #include "SimpleTimeInterval.h" 00002 #include "SimpleTimeDuration.h" 00003 00005 // Construction 00007 SimpleTimeInterval::SimpleTimeInterval(const SimpleTimeInterval &i) { 00008 setInterval(i); 00009 } 00010 00011 SimpleTimeInterval::SimpleTimeInterval(const SimpleTime & start, 00012 const SimpleTime & end) { 00013 setInterval(start, end); 00014 } 00015 00017 // Comparison 00019 bool SimpleTimeInterval:: 00020 contains(const SimpleTimeInterval& comparison) const { 00021 return (startPoint.isBefore(comparison.start()) && 00022 comparison.end().isBefore(endPoint)); 00023 } 00024 00025 bool SimpleTimeInterval::contains(const SimpleTime& comparison) const { 00026 return (startPoint.isBefore(comparison) && 00027 comparison.isBefore(endPoint)); 00028 } 00029 00030 bool 00031 SimpleTimeInterval::overlapsWith(const SimpleTimeInterval& comparison) const { 00032 return (!endsBefore(comparison) || !startsAfter(comparison)); 00033 } 00034 00035 bool 00036 SimpleTimeInterval::endsBefore(const SimpleTimeInterval& comparison) const { 00037 return(endPoint.isBefore(comparison.start())); 00038 } 00039 00040 bool 00041 SimpleTimeInterval::startsAfter(const SimpleTimeInterval& comparison) const { 00042 return(comparison.end().isBefore(startPoint)); 00043 } 00044 00046 // Aux. fcns 00048 00049 void SimpleTimeInterval::setInterval(const SimpleTimeInterval & i) { 00050 startPoint=i.start(); 00051 endPoint=i.end(); 00052 } 00053 00054 void SimpleTimeInterval::setInterval(const SimpleTime & start, 00055 const SimpleTime & end) { 00056 if (end.isBefore(start)) { 00057 setInterval(end, start); // Reverse the order 00058 return; 00059 } 00060 setStart(start); 00061 setEnd(end); 00062 } 00063 00064 SimpleTimeDuration SimpleTimeInterval::duration() const { 00065 SimpleTimeDuration d; 00066 d.setDuration(*this); 00067 return d; 00068 } 00069 00070 SimpleTime SimpleTimeInterval::start() const { 00071 return startPoint; 00072 } 00073 00074 SimpleTime SimpleTimeInterval::end() const { 00075 return endPoint; 00076 } 00077 00078 void SimpleTimeInterval::setStart(const SimpleTime & newStart) { 00079 if (end().isBefore(newStart)) { 00080 return; // TODO: Throw an exception 00081 } 00082 startPoint = newStart; 00083 } 00084 00085 void SimpleTimeInterval::setEnd(const SimpleTime & newEnd) { 00086 if (newEnd.isBefore(start())) { 00087 return; // TODO: Throw an exception 00088 } 00089 endPoint = newEnd; 00090 }