Ticket #12963: utilities_ptime.cpp

File utilities_ptime.cpp, 1002 bytes (added by Willi Burkhardt <willi.burkhardt@…>, 6 years ago)

global function that I use as workaround for the problem

Line 
1#include "utilities_ptime.h"
2
3
4#include <boost/date_time/posix_time/posix_time_types.hpp>
5
6
7
8using boost::posix_time::time_period;
9using 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///
23auto 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}