Newer
Older
#include "MantidKernel/DateAndTime.h"
#include <boost/date_time/date.hpp>
#include <boost/date_time/time.hpp>
#include <boost/lexical_cast.hpp>
#include <cmath>
#include <exception>
#include <limits>
#include <memory>
#include <ostream>
#include <stdexcept>
namespace Mantid {
using namespace Types::Core;
namespace Kernel {
TimeInterval::TimeInterval(const Types::Core::DateAndTime &from,
const Types::Core::DateAndTime &to)
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
: m_begin(from) {
if (to > from)
m_end = to;
else
m_end = from;
}
/** Returns an intersection of this interval with \a ti
@param ti :: Time interval
@return A valid time interval if this interval intersects with \a ti or
an empty interval otherwise.
*/
TimeInterval TimeInterval::intersection(const TimeInterval &ti) const {
if (!isValid() || !ti.isValid())
return TimeInterval();
DateAndTime t1 = begin();
if (ti.begin() > t1)
t1 = ti.begin();
DateAndTime t2 = end();
if (ti.end() < t2)
t2 = ti.end();
return t1 < t2 ? TimeInterval(t1, t2) : TimeInterval();
}
/// String representation of the begin time
std::string TimeInterval::begin_str() const {
return boost::posix_time::to_simple_string(this->m_begin.to_ptime());
}
/// String representation of the end time
std::string TimeInterval::end_str() const {
return boost::posix_time::to_simple_string(this->m_end.to_ptime());
}
std::ostream &operator<<(std::ostream &s,
const Mantid::Kernel::TimeInterval &t) {
s << t.begin().toSimpleString() << " - " << t.end().toSimpleString();
return s;
}
} // namespace Kernel
} // namespace Mantid