1 #ifndef LOCAL_TIME_DATE_DURATION_OPERATORS_HPP___
2 #define LOCAL_TIME_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/local_time/local_date_time.hpp"
16 namespace local_time
{
18 /*!@file date_duration_operators.hpp Operators for local_date_time 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 local_date_time. Result will be same
27 * day-of-month as local_date_time unless original day was the last day of month.
28 * see date_time::months_duration for more details */
31 operator+(const local_date_time
& t
, const boost::gregorian::months
& m
)
33 return t
+ m
.get_offset(t
.utc_time().date());
36 /*! Adds a months object to a local_date_time. Result will be same
37 * day-of-month as local_date_time unless original day was the last day of month.
38 * see date_time::months_duration for more details */
41 operator+=(local_date_time
& t
, const boost::gregorian::months
& m
)
43 return t
+= m
.get_offset(t
.utc_time().date());
46 /*! Subtracts a months object and a local_date_time. Result will be same
47 * day-of-month as local_date_time unless original day was the last day of month.
48 * see date_time::months_duration for more details */
51 operator-(const local_date_time
& t
, const boost::gregorian::months
& m
)
53 // get_neg_offset returns a negative duration, so we add
54 return t
+ m
.get_neg_offset(t
.utc_time().date());
57 /*! Subtracts a months object from a local_date_time. Result will be same
58 * day-of-month as local_date_time unless original day was the last day of month.
59 * see date_time::months_duration for more details */
62 operator-=(local_date_time
& t
, const boost::gregorian::months
& m
)
64 // get_neg_offset returns a negative duration, so we add
65 return t
+= m
.get_neg_offset(t
.utc_time().date());
68 // local_date_time & years
70 /*! Adds a years object and a local_date_time. Result will be same
71 * month and day-of-month as local_date_time unless original day was the
72 * last day of month. see date_time::years_duration for more details */
75 operator+(const local_date_time
& t
, const boost::gregorian::years
& y
)
77 return t
+ y
.get_offset(t
.utc_time().date());
80 /*! Adds a years object to a local_date_time. Result will be same
81 * month and day-of-month as local_date_time unless original day was the
82 * last day of month. see date_time::years_duration for more details */
85 operator+=(local_date_time
& t
, const boost::gregorian::years
& y
)
87 return t
+= y
.get_offset(t
.utc_time().date());
90 /*! Subtracts a years object and a local_date_time. Result will be same
91 * month and day-of-month as local_date_time unless original day was the
92 * last day of month. see date_time::years_duration for more details */
95 operator-(const local_date_time
& 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
.utc_time().date());
101 /*! Subtracts a years object from a local_date_time. Result will be same
102 * month and day-of-month as local_date_time unless original day was the
103 * last day of month. see date_time::years_duration for more details */
106 operator-=(local_date_time
& 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
.utc_time().date());
115 #endif // LOCAL_TIME_DATE_DURATION_OPERATORS_HPP___