Mantid
Loading...
Searching...
No Matches
DateAndTime.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
9#include <boost/date_time/date.hpp>
10#include <boost/date_time/time.hpp>
11
12#include <cmath>
13#include <exception>
14#include <limits>
15#include <memory>
16#include <ostream>
17#include <stdexcept>
18
19namespace Mantid {
20
21using namespace Types::Core;
22namespace Kernel {
23
24TimeInterval::TimeInterval(const Types::Core::DateAndTime &from, const Types::Core::DateAndTime &to) : m_begin(from) {
25 if (to > from)
26 m_end = to;
27 else
28 m_end = from;
29}
30
37 if (!isValid() || !ti.isValid())
38 return TimeInterval();
39
40 DateAndTime t1 = begin();
41 if (ti.begin() > t1)
42 t1 = ti.begin();
43
44 DateAndTime t2 = end();
45 if (ti.end() < t2)
46 t2 = ti.end();
47
48 return t1 < t2 ? TimeInterval(t1, t2) : TimeInterval();
49}
50
52std::string TimeInterval::begin_str() const { return boost::posix_time::to_simple_string(this->m_begin.to_ptime()); }
53
55std::string TimeInterval::end_str() const { return boost::posix_time::to_simple_string(this->m_end.to_ptime()); }
56
57std::ostream &operator<<(std::ostream &s, const Mantid::Kernel::TimeInterval &t) {
58 s << t.begin().toSimpleString() << " - " << t.end().toSimpleString();
59 return s;
60}
61
62} // namespace Kernel
63
64} // namespace Mantid
Represents a time interval.
Definition: DateAndTime.h:25
TimeInterval()
Default constructor.
Definition: DateAndTime.h:28
Types::Core::DateAndTime m_end
end
Definition: DateAndTime.h:59
Types::Core::DateAndTime begin() const
Beginning of the interval.
Definition: DateAndTime.h:32
bool isValid() const
True if the interval is not empty.
Definition: DateAndTime.h:36
Types::Core::DateAndTime end() const
End of the interval.
Definition: DateAndTime.h:34
TimeInterval intersection(const TimeInterval &ti) const
Returns an intersection of two intervals.
Definition: DateAndTime.cpp:36
Types::Core::DateAndTime m_begin
begin
Definition: DateAndTime.h:57
std::string end_str() const
String representation of the end time.
Definition: DateAndTime.cpp:55
std::string begin_str() const
String representation of the begin time.
Definition: DateAndTime.cpp:52
MANTID_KERNEL_DLL std::ostream & operator<<(std::ostream &, CPUTimer &)
Convenience function to provide for easier debug printing.
Definition: CPUTimer.cpp:86
Helper class which provides the Collimation Length for SANS instruments.