1#ifndef DATE_DURATION_OPERATORS_HPP___
2#define DATE_DURATION_OPERATORS_HPP___
3
4/* Copyright (c) 2004 CrystalClear Software, Inc.
5 * Subject to the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE_1_0.txt or
7 * http://www.boost.org/LICENSE_1_0.txt)
8 * Author: Jeff Garland, Bart Garst
9 * $Date$
10 */
11
12#include "boost/date_time/gregorian/greg_duration_types.hpp"
13#include "boost/date_time/posix_time/ptime.hpp"
14
15namespace boost {
16namespace posix_time {
17
18 /*!@file date_duration_operators.hpp Operators for ptime and
19 * optional gregorian types. Operators use snap-to-end-of-month behavior.
20 * Further details on this behavior can be found in reference for
21 * date_time/date_duration_types.hpp and documentation for
22 * month and year iterators.
23 */
24
25
26 /*! Adds a months object and a ptime. Result will be same
27 * day-of-month as ptime unless original day was the last day of month.
28 * see date_time::months_duration for more details */
29 inline
30 ptime
31 operator+(const ptime& t, const boost::gregorian::months& m)
32 {
33 return t + m.get_offset(d: t.date());
34 }
35
36 /*! Adds a months object to a ptime. Result will be same
37 * day-of-month as ptime unless original day was the last day of month.
38 * see date_time::months_duration for more details */
39 inline
40 ptime
41 operator+=(ptime& t, const boost::gregorian::months& m)
42 {
43 // get_neg_offset returns a negative duration, so we add
44 return t += m.get_offset(d: t.date());
45 }
46
47 /*! Subtracts a months object and a ptime. Result will be same
48 * day-of-month as ptime unless original day was the last day of month.
49 * see date_time::months_duration for more details */
50 inline
51 ptime
52 operator-(const ptime& t, const boost::gregorian::months& m)
53 {
54 // get_neg_offset returns a negative duration, so we add
55 return t + m.get_neg_offset(d: t.date());
56 }
57
58 /*! Subtracts a months object from a ptime. Result will be same
59 * day-of-month as ptime unless original day was the last day of month.
60 * see date_time::months_duration for more details */
61 inline
62 ptime
63 operator-=(ptime& t, const boost::gregorian::months& m)
64 {
65 return t += m.get_neg_offset(d: t.date());
66 }
67
68 // ptime & years
69
70 /*! Adds a years object and a ptime. Result will be same
71 * month and day-of-month as ptime unless original day was the
72 * last day of month. see date_time::years_duration for more details */
73 inline
74 ptime
75 operator+(const ptime& t, const boost::gregorian::years& y)
76 {
77 return t + y.get_offset(d: t.date());
78 }
79
80 /*! Adds a years object to a ptime. Result will be same
81 * month and day-of-month as ptime unless original day was the
82 * last day of month. see date_time::years_duration for more details */
83 inline
84 ptime
85 operator+=(ptime& t, const boost::gregorian::years& y)
86 {
87 return t += y.get_offset(d: t.date());
88 }
89
90 /*! Subtracts a years object and a ptime. Result will be same
91 * month and day-of-month as ptime unless original day was the
92 * last day of month. see date_time::years_duration for more details */
93 inline
94 ptime
95 operator-(const ptime& t, const boost::gregorian::years& y)
96 {
97 // get_neg_offset returns a negative duration, so we add
98 return t + y.get_neg_offset(d: t.date());
99 }
100
101 /*! Subtracts a years object from a ptime. Result will be same
102 * month and day-of-month as ptime unless original day was the
103 * last day of month. see date_time::years_duration for more details */
104 inline
105 ptime
106 operator-=(ptime& t, const boost::gregorian::years& y)
107 {
108 // get_neg_offset returns a negative duration, so we add
109 return t += y.get_neg_offset(d: t.date());
110 }
111
112}} // namespaces
113
114#endif // DATE_DURATION_OPERATORS_HPP___
115

source code of boost/boost/date_time/posix_time/date_duration_operators.hpp