1 #ifndef LOCAL_TIME_DATE_DURATION_OPERATORS_HPP___ 2 #define LOCAL_TIME_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/local_time/local_date_time.hpp" 14 15 namespace boost { 16 namespace local_time { 17 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. 23 */ 24 25 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 */ 29 inline 30 local_date_time operator +(const local_date_time & t,const boost::gregorian::months & m)31 operator+(const local_date_time& t, const boost::gregorian::months& m) 32 { 33 return t + m.get_offset(t.utc_time().date()); 34 } 35 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 */ 39 inline 40 local_date_time operator +=(local_date_time & t,const boost::gregorian::months & m)41 operator+=(local_date_time& t, const boost::gregorian::months& m) 42 { 43 return t += m.get_offset(t.utc_time().date()); 44 } 45 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 */ 49 inline 50 local_date_time operator -(const local_date_time & t,const boost::gregorian::months & m)51 operator-(const local_date_time& t, const boost::gregorian::months& m) 52 { 53 // get_neg_offset returns a negative duration, so we add 54 return t + m.get_neg_offset(t.utc_time().date()); 55 } 56 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 */ 60 inline 61 local_date_time operator -=(local_date_time & t,const boost::gregorian::months & m)62 operator-=(local_date_time& t, const boost::gregorian::months& m) 63 { 64 // get_neg_offset returns a negative duration, so we add 65 return t += m.get_neg_offset(t.utc_time().date()); 66 } 67 68 // local_date_time & years 69 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 */ 73 inline 74 local_date_time operator +(const local_date_time & t,const boost::gregorian::years & y)75 operator+(const local_date_time& t, const boost::gregorian::years& y) 76 { 77 return t + y.get_offset(t.utc_time().date()); 78 } 79 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 */ 83 inline 84 local_date_time operator +=(local_date_time & t,const boost::gregorian::years & y)85 operator+=(local_date_time& t, const boost::gregorian::years& y) 86 { 87 return t += y.get_offset(t.utc_time().date()); 88 } 89 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 */ 93 inline 94 local_date_time operator -(const local_date_time & t,const boost::gregorian::years & y)95 operator-(const local_date_time& 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(t.utc_time().date()); 99 } 100 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 */ 104 inline 105 local_date_time operator -=(local_date_time & t,const boost::gregorian::years & y)106 operator-=(local_date_time& 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(t.utc_time().date()); 110 } 111 112 113 }} // namespaces 114 115 #endif // LOCAL_TIME_DATE_DURATION_OPERATORS_HPP___ 116