File indexing completed on 2025-01-30 09:35:21
0001 #ifndef DATE_TIME_DATE_DURATION__
0002 #define DATE_TIME_DATE_DURATION__
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <boost/operators.hpp>
0014 #include <boost/date_time/special_defs.hpp>
0015 #include <boost/date_time/compiler_config.hpp>
0016 #include <boost/date_time/int_adapter.hpp>
0017
0018 namespace boost {
0019 namespace date_time {
0020
0021
0022
0023 template<class duration_rep_traits>
0024 class BOOST_SYMBOL_VISIBLE date_duration : private
0025 boost::less_than_comparable1< date_duration< duration_rep_traits >
0026 , boost::equality_comparable1< date_duration< duration_rep_traits >
0027 , boost::addable1< date_duration< duration_rep_traits >
0028 , boost::subtractable1< date_duration< duration_rep_traits >
0029 , boost::dividable2< date_duration< duration_rep_traits >, int
0030 > > > > >
0031 {
0032 public:
0033 typedef typename duration_rep_traits::int_type duration_rep_type;
0034 typedef typename duration_rep_traits::impl_type duration_rep;
0035
0036
0037 BOOST_CXX14_CONSTEXPR explicit date_duration(duration_rep day_count) : days_(day_count) {}
0038
0039
0040
0041 BOOST_CXX14_CONSTEXPR date_duration(special_values sv) :
0042 days_(duration_rep::from_special(sv))
0043 {}
0044
0045
0046 BOOST_CXX14_CONSTEXPR duration_rep get_rep()const
0047 {
0048 return days_;
0049 }
0050 BOOST_CXX14_CONSTEXPR special_values as_special() const
0051 {
0052 return days_.as_special();
0053 }
0054 BOOST_CXX14_CONSTEXPR bool is_special()const
0055 {
0056 return days_.is_special();
0057 }
0058
0059 BOOST_CXX14_CONSTEXPR duration_rep_type days() const
0060 {
0061 return duration_rep_traits::as_number(days_);
0062 }
0063
0064 static BOOST_CXX14_CONSTEXPR date_duration unit()
0065 {
0066 return date_duration<duration_rep_traits>(1);
0067 }
0068
0069 BOOST_CXX14_CONSTEXPR bool operator==(const date_duration& rhs) const
0070 {
0071 return days_ == rhs.days_;
0072 }
0073
0074 BOOST_CXX14_CONSTEXPR bool operator<(const date_duration& rhs) const
0075 {
0076 return days_ < rhs.days_;
0077 }
0078
0079
0080
0081
0082
0083
0084
0085 BOOST_CXX14_CONSTEXPR date_duration& operator-=(const date_duration& rhs)
0086 {
0087
0088 days_ = days_ - rhs.days_;
0089 return *this;
0090 }
0091
0092 BOOST_CXX14_CONSTEXPR date_duration& operator+=(const date_duration& rhs)
0093 {
0094 days_ = days_ + rhs.days_;
0095 return *this;
0096 }
0097
0098
0099 BOOST_CXX14_CONSTEXPR date_duration operator-() const
0100 {
0101 return date_duration<duration_rep_traits>(get_rep() * (-1));
0102 }
0103
0104 BOOST_CXX14_CONSTEXPR date_duration& operator/=(int divisor)
0105 {
0106 days_ = days_ / divisor;
0107 return *this;
0108 }
0109
0110
0111 BOOST_CXX14_CONSTEXPR bool is_negative() const
0112 {
0113 return days_ < 0;
0114 }
0115
0116 private:
0117 duration_rep days_;
0118 };
0119
0120
0121
0122
0123
0124 struct BOOST_SYMBOL_VISIBLE duration_traits_long
0125 {
0126 typedef long int_type;
0127 typedef long impl_type;
0128 static BOOST_CXX14_CONSTEXPR int_type as_number(impl_type i) { return i; }
0129 };
0130
0131
0132
0133
0134 struct BOOST_SYMBOL_VISIBLE duration_traits_adapted
0135 {
0136 typedef long int_type;
0137 typedef boost::date_time::int_adapter<long> impl_type;
0138 static BOOST_CXX14_CONSTEXPR int_type as_number(impl_type i) { return i.as_number(); }
0139 };
0140
0141
0142 } }
0143
0144
0145 #endif
0146