1 | #include "utilities_ptime.h"
|
---|
2 |
|
---|
3 |
|
---|
4 | #include <boost/date_time/posix_time/posix_time_types.hpp>
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 | using boost::posix_time::time_period;
|
---|
9 | using boost::posix_time::not_a_date_time;
|
---|
10 |
|
---|
11 | ///
|
---|
12 | /// \brief time_period_span
|
---|
13 | /// Combines two periods and any gap between them such that
|
---|
14 | /// begin = min(p1.begin, p2.begin) and
|
---|
15 | /// end = max(p1.end , p2.end).
|
---|
16 | /// If one of the periods is invalid, the other period is returned. If both
|
---|
17 | /// periods are invalid, the returned period is invalid.
|
---|
18 | ///
|
---|
19 | /// \param left
|
---|
20 | /// \param right
|
---|
21 | /// \return
|
---|
22 | ///
|
---|
23 | auto time_period_span(time_period & left, time_period & right) -> time_period
|
---|
24 | {
|
---|
25 | time_period rv(left);
|
---|
26 | if(rv.begin().is_special() || rv.is_null())
|
---|
27 | {
|
---|
28 | rv = right;
|
---|
29 | if(rv.begin().is_special() || rv.is_null())
|
---|
30 | {
|
---|
31 | // both arguments are not_a_date_time -> set result invalid
|
---|
32 | rv.begin() = not_a_date_time;
|
---|
33 | }
|
---|
34 | }
|
---|
35 | else
|
---|
36 | {
|
---|
37 | if(!(right.begin().is_special() || right.is_null()))
|
---|
38 | {
|
---|
39 | rv = rv.span(right);
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | return rv;
|
---|
44 | }
|
---|