diff --git a/include/boost/date_time/posix_time/date_duration_operators.hpp b/include/boost/date_time/posix_time/date_duration_operators.hpp new file mode 100644 index 0000000..159971d --- /dev/null +++ b/include/boost/date_time/posix_time/date_duration_operators.hpp @@ -0,0 +1,60 @@ +#ifndef DATE_DURATION_OPERATORS_HPP___ +#define DATE_DURATION_OPERATORS_HPP___ + +/* Copyright (c) 2004 CrystalClear Software, Inc. + * Subject to the Boost Software License, Version 1.0. + * (See accompanying file LICENSE-1.0 or + * http://www.boost.org/LICENSE-1.0) + * Author: Jeff Garland, Bart Garst + * $Date$ + */ + +#include "boost/date_time/gregorian/greg_duration_types.hpp" +#include "boost/date_time/posix_time/ptime.hpp" + +namespace boost { +namespace posix_time { + + /*** ptime operator functions ***/ + // ptime & months + ptime operator+(const ptime& t, const boost::gregorian::months& m) + { + return t + m.get_offset(t.date()); + } + ptime operator+=(ptime& t, const boost::gregorian::months& m) + { + // get_neg_offset returns a negative duration, so we add + return t += m.get_offset(t.date()); + } + ptime operator-(const ptime& t, const boost::gregorian::months& m) + { + // get_neg_offset returns a negative duration, so we add + return t + m.get_neg_offset(t.date()); + } + ptime operator-=(ptime& t, const boost::gregorian::months& m) + { + return t += m.get_neg_offset(t.date()); + } + // ptime & years + ptime operator+(const ptime& t, const boost::gregorian::years& y) + { + return t + y.get_offset(t.date()); + } + ptime operator+=(ptime& t, const boost::gregorian::years& y) + { + return t += y.get_offset(t.date()); + } + ptime operator-(const ptime& t, const boost::gregorian::years& y) + { + // get_neg_offset returns a negative duration, so we add + return t + y.get_neg_offset(t.date()); + } + ptime operator-=(ptime& t, const boost::gregorian::years& y) + { + // get_neg_offset returns a negative duration, so we add + return t += y.get_neg_offset(t.date()); + } + +}} // namespaces + +#endif // DATE_DURATION_OPERATORS_HPP___ diff --git a/include/boost/date_time/posix_time/posix_time.hpp b/include/boost/date_time/posix_time/posix_time.hpp index aafa03d..292bc25 100644 --- a/include/boost/date_time/posix_time/posix_time.hpp +++ b/include/boost/date_time/posix_time/posix_time.hpp @@ -13,6 +13,9 @@ #include "boost/date_time/compiler_config.hpp" #include "boost/date_time/posix_time/ptime.hpp" +#if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES) +#include "boost/date_time/posix_time/date_duration_operators.hpp" +#endif #if defined(BOOST_DATE_TIME_NO_WSTRING_CONVERSIONS) #include "boost/date_time/posix_time/time_formatters_limited.hpp" #else diff --git a/include/boost/date_time/posix_time/posix_time_types.hpp b/include/boost/date_time/posix_time/posix_time_types.hpp index 0c28906..a603b1f 100644 --- a/include/boost/date_time/posix_time/posix_time_types.hpp +++ b/include/boost/date_time/posix_time/posix_time_types.hpp @@ -10,6 +10,9 @@ #include "boost/date_time/time_clock.hpp" #include "boost/date_time/microsec_time_clock.hpp" #include "boost/date_time/posix_time/ptime.hpp" +#if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES) +#include "boost/date_time/posix_time/date_duration_operators.hpp" +#endif #include "boost/date_time/posix_time/posix_time_duration.hpp" #include "boost/date_time/posix_time/posix_time_system.hpp" #include "boost/date_time/posix_time/time_period.hpp"