File indexing completed on 2025-01-30 09:35:21
0001 #ifndef DATE_TIME_DATE_HPP___
0002 #define DATE_TIME_DATE_HPP___
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <boost/operators.hpp>
0013 #include <boost/date_time/compiler_config.hpp>
0014 #include <boost/date_time/year_month_day.hpp>
0015 #include <boost/date_time/special_defs.hpp>
0016
0017 namespace boost {
0018 namespace date_time {
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 template<class T, class calendar, class duration_type_>
0054 class BOOST_SYMBOL_VISIBLE date : private
0055 boost::less_than_comparable<T
0056 , boost::equality_comparable<T
0057 > >
0058 {
0059 public:
0060 typedef T date_type;
0061 typedef calendar calendar_type;
0062 typedef typename calendar::date_traits_type traits_type;
0063 typedef duration_type_ duration_type;
0064 typedef typename calendar::year_type year_type;
0065 typedef typename calendar::month_type month_type;
0066 typedef typename calendar::day_type day_type;
0067 typedef typename calendar::ymd_type ymd_type;
0068 typedef typename calendar::date_rep_type date_rep_type;
0069 typedef typename calendar::date_int_type date_int_type;
0070 typedef typename calendar::day_of_week_type day_of_week_type;
0071 BOOST_CXX14_CONSTEXPR date(year_type y, month_type m, day_type d)
0072 : days_(calendar::day_number(ymd_type(y, m, d)))
0073 {}
0074 BOOST_CXX14_CONSTEXPR date(const ymd_type& ymd)
0075 : days_(calendar::day_number(ymd))
0076 {}
0077
0078 BOOST_CXX14_CONSTEXPR year_type year() const
0079 {
0080 ymd_type ymd = calendar::from_day_number(days_);
0081 return ymd.year;
0082 }
0083 BOOST_CXX14_CONSTEXPR month_type month() const
0084 {
0085 ymd_type ymd = calendar::from_day_number(days_);
0086 return ymd.month;
0087 }
0088 BOOST_CXX14_CONSTEXPR day_type day() const
0089 {
0090 ymd_type ymd = calendar::from_day_number(days_);
0091 return ymd.day;
0092 }
0093 BOOST_CXX14_CONSTEXPR day_of_week_type day_of_week() const
0094 {
0095 ymd_type ymd = calendar::from_day_number(days_);
0096 return calendar::day_of_week(ymd);
0097 }
0098 BOOST_CXX14_CONSTEXPR ymd_type year_month_day() const
0099 {
0100 return calendar::from_day_number(days_);
0101 }
0102 BOOST_CONSTEXPR bool operator<(const date_type& rhs) const
0103 {
0104 return days_ < rhs.days_;
0105 }
0106 BOOST_CONSTEXPR bool operator==(const date_type& rhs) const
0107 {
0108 return days_ == rhs.days_;
0109 }
0110
0111 BOOST_CONSTEXPR bool is_special()const
0112 {
0113 return(is_not_a_date() || is_infinity());
0114 }
0115
0116 BOOST_CONSTEXPR bool is_not_a_date() const
0117 {
0118 return traits_type::is_not_a_number(days_);
0119 }
0120
0121 BOOST_CONSTEXPR bool is_infinity() const
0122 {
0123 return traits_type::is_inf(days_);
0124 }
0125
0126 BOOST_CONSTEXPR bool is_pos_infinity() const
0127 {
0128 return traits_type::is_pos_inf(days_);
0129 }
0130
0131 BOOST_CONSTEXPR bool is_neg_infinity() const
0132 {
0133 return traits_type::is_neg_inf(days_);
0134 }
0135
0136 BOOST_CXX14_CONSTEXPR special_values as_special() const
0137 {
0138 return traits_type::to_special(days_);
0139 }
0140 BOOST_CXX14_CONSTEXPR duration_type operator-(const date_type& d) const
0141 {
0142 if (!this->is_special() && !d.is_special())
0143 {
0144
0145
0146 typedef typename duration_type::duration_rep_type duration_rep_type;
0147 return duration_type(static_cast< duration_rep_type >(days_) - static_cast< duration_rep_type >(d.days_));
0148 }
0149 else
0150 {
0151
0152 date_rep_type val = date_rep_type(days_) - date_rep_type(d.days_);
0153 return duration_type(val.as_special());
0154 }
0155 }
0156
0157 BOOST_CXX14_CONSTEXPR date_type operator-(const duration_type& dd) const
0158 {
0159 if(dd.is_special())
0160 {
0161 return date_type(date_rep_type(days_) - dd.get_rep());
0162 }
0163 return date_type(date_rep_type(days_) - static_cast<date_int_type>(dd.days()));
0164 }
0165 BOOST_CXX14_CONSTEXPR date_type operator-=(const duration_type& dd)
0166 {
0167 *this = *this - dd;
0168 return date_type(days_);
0169 }
0170 BOOST_CONSTEXPR date_rep_type day_count() const
0171 {
0172 return days_;
0173 }
0174
0175 BOOST_CXX14_CONSTEXPR date_type operator+(const duration_type& dd) const
0176 {
0177 if(dd.is_special())
0178 {
0179 return date_type(date_rep_type(days_) + dd.get_rep());
0180 }
0181 return date_type(date_rep_type(days_) + static_cast<date_int_type>(dd.days()));
0182 }
0183 BOOST_CXX14_CONSTEXPR date_type operator+=(const duration_type& dd)
0184 {
0185 *this = *this + dd;
0186 return date_type(days_);
0187 }
0188
0189
0190 protected:
0191
0192
0193
0194
0195 BOOST_CONSTEXPR explicit date(date_int_type days) : days_(days) {}
0196 BOOST_CXX14_CONSTEXPR explicit date(date_rep_type days) : days_(days.as_number()) {}
0197 date_int_type days_;
0198
0199 };
0200
0201
0202
0203
0204 } }
0205
0206
0207
0208
0209 #endif