StdAir Logo  1.00.21
C++ Standard Airline IT Object Library
Loading...
Searching...
No Matches
PeriodStruct.cpp
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <sstream>
6#include <cassert>
7// StdAir
10
11namespace stdair {
12
13 // ////////////////////////////////////////////////////////////////////
15 : _dateRange (BOOST_DEFAULT_DATE_PERIOD), _dow () {
16 }
17
18 // ////////////////////////////////////////////////////////////////////
20 const DoWStruct& iDoW)
21 : _dateRange (iDateRange), _dow (iDoW) {
22 }
23
24 // ////////////////////////////////////////////////////////////////////
26 : _dateRange (iPeriodStruct._dateRange), _dow (iPeriodStruct._dow) {
27
28 }
29
30 // ////////////////////////////////////////////////////////////////////
31 const std::string PeriodStruct::describeShort() const {
32 std::ostringstream ostr;
33 ostr << _dateRange << ", " << _dow.describeShort ();
34 return ostr.str();
35 }
36
37 // ////////////////////////////////////////////////////////////////////
38 const std::string PeriodStruct::describe() const {
39 std::ostringstream ostr;
40 ostr << _dateRange << ", " << _dow.describe ();
41 return ostr.str();
42 }
43
44 // ////////////////////////////////////////////////////////////////////
46 addDateOffset (const DateOffset_T& iDateOffset) const {
47 // Create a new date range by shifting the date range of this object with
48 // iDateOffset.
49 DatePeriod_T lNewDateRange = getDateRange();
50 lNewDateRange.shift (iDateOffset);
51
52 // Create a new DoWStruct by shifting the DoWStruct of this object with
53 // iDateOffset.
54 const long lNbOfDaysOffset = iDateOffset.days();
55 const DoWStruct& lDoW = getDoW();
56 const DoWStruct lNewDoW = lDoW.shift (lNbOfDaysOffset);
57
58 return PeriodStruct (lNewDateRange, lNewDoW);
59 }
60
61 // ////////////////////////////////////////////////////////////////////
63 intersection (const PeriodStruct& iPeriodStruct) const {
64 const DatePeriod_T lNewDateRange =
65 _dateRange.intersection (iPeriodStruct._dateRange);
66 const DoWStruct lNewDoW = _dow.intersection (iPeriodStruct._dow);
67
68 return PeriodStruct (lNewDateRange, lNewDoW);
69 }
70
71 // ////////////////////////////////////////////////////////////////////
72 const bool PeriodStruct::isValid () const {
73 if (_dateRange.is_null() == false && _dow.isValid()) {
74 return true;
75 }
76 return false;
77 }
78
79}
Handle on the StdAir library context.
boost::gregorian::date_duration DateOffset_T
const DatePeriod_T BOOST_DEFAULT_DATE_PERIOD
boost::gregorian::date_period DatePeriod_T
DoWStruct intersection(const DoWStruct &) const
DoWStruct shift(const long &) const
Definition DoWStruct.cpp:88
const DatePeriod_T & getDateRange() const
const std::string describeShort() const
PeriodStruct(const DatePeriod_T &, const DoWStruct &)
const std::string describe() const
const DoWStruct & getDoW() const
PeriodStruct addDateOffset(const DateOffset_T &) const
const bool isValid() const
PeriodStruct intersection(const PeriodStruct &) const