1 #ifndef DATE_DURATION_OPERATORS_HPP___
2 #define DATE_DURATION_OPERATORS_HPP___
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
12 #include "boost/date_time/gregorian/greg_duration_types.hpp"
13 #include "boost/date_time/posix_time/ptime.hpp"
16 namespace posix_time
{
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.
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 */
31 operator+(const ptime
& t
, const boost::gregorian::months
& m
)
33 return t
+ m
.get_offset(t
.date());
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 */
41 operator+=(ptime
& t
, const boost::gregorian::months
& m
)
43 // get_neg_offset returns a negative duration, so we add
44 return t
+= m
.get_offset(t
.date());
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 */
52 operator-(const ptime
& t
, const boost::gregorian::months
& m
)
54 // get_neg_offset returns a negative duration, so we add
55 return t
+ m
.get_neg_offset(t
.date());
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 */
63 operator-=(ptime
& t
, const boost::gregorian::months
& m
)
65 return t
+= m
.get_neg_offset(t
.date());
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 */
75 operator+(const ptime
& t
, const boost::gregorian::years
& y
)
77 return t
+ y
.get_offset(t
.date());
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 */
85 operator+=(ptime
& t
, const boost::gregorian::years
& y
)
87 return t
+= y
.get_offset(t
.date());
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 */
95 operator-(const ptime
& t
, const boost::gregorian::years
& y
)
97 // get_neg_offset returns a negative duration, so we add
98 return t
+ y
.get_neg_offset(t
.date());
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 */
106 operator-=(ptime
& t
, const boost::gregorian::years
& y
)
108 // get_neg_offset returns a negative duration, so we add
109 return t
+= y
.get_neg_offset(t
.date());
114 #endif // DATE_DURATION_OPERATORS_HPP___