123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- #ifndef DATE_TIME_DATE_HPP___
- #define DATE_TIME_DATE_HPP___
- #include <boost/operators.hpp>
- #include <boost/date_time/compiler_config.hpp>
- #include <boost/date_time/year_month_day.hpp>
- #include <boost/date_time/special_defs.hpp>
- namespace boost {
- namespace date_time {
-
-
- template<class T, class calendar, class duration_type_>
- class BOOST_SYMBOL_VISIBLE date : private
- boost::less_than_comparable<T
- , boost::equality_comparable<T
- > >
- {
- public:
- typedef T date_type;
- typedef calendar calendar_type;
- typedef typename calendar::date_traits_type traits_type;
- typedef duration_type_ duration_type;
- typedef typename calendar::year_type year_type;
- typedef typename calendar::month_type month_type;
- typedef typename calendar::day_type day_type;
- typedef typename calendar::ymd_type ymd_type;
- typedef typename calendar::date_rep_type date_rep_type;
- typedef typename calendar::date_int_type date_int_type;
- typedef typename calendar::day_of_week_type day_of_week_type;
- BOOST_CXX14_CONSTEXPR date(year_type y, month_type m, day_type d)
- : days_(calendar::day_number(ymd_type(y, m, d)))
- {}
- BOOST_CXX14_CONSTEXPR date(const ymd_type& ymd)
- : days_(calendar::day_number(ymd))
- {}
-
- BOOST_CXX14_CONSTEXPR year_type year() const
- {
- ymd_type ymd = calendar::from_day_number(days_);
- return ymd.year;
- }
- BOOST_CXX14_CONSTEXPR month_type month() const
- {
- ymd_type ymd = calendar::from_day_number(days_);
- return ymd.month;
- }
- BOOST_CXX14_CONSTEXPR day_type day() const
- {
- ymd_type ymd = calendar::from_day_number(days_);
- return ymd.day;
- }
- BOOST_CXX14_CONSTEXPR day_of_week_type day_of_week() const
- {
- ymd_type ymd = calendar::from_day_number(days_);
- return calendar::day_of_week(ymd);
- }
- BOOST_CXX14_CONSTEXPR ymd_type year_month_day() const
- {
- return calendar::from_day_number(days_);
- }
- BOOST_CONSTEXPR bool operator<(const date_type& rhs) const
- {
- return days_ < rhs.days_;
- }
- BOOST_CONSTEXPR bool operator==(const date_type& rhs) const
- {
- return days_ == rhs.days_;
- }
-
- BOOST_CONSTEXPR bool is_special()const
- {
- return(is_not_a_date() || is_infinity());
- }
-
- BOOST_CONSTEXPR bool is_not_a_date() const
- {
- return traits_type::is_not_a_number(days_);
- }
-
- BOOST_CONSTEXPR bool is_infinity() const
- {
- return traits_type::is_inf(days_);
- }
-
- BOOST_CONSTEXPR bool is_pos_infinity() const
- {
- return traits_type::is_pos_inf(days_);
- }
-
- BOOST_CONSTEXPR bool is_neg_infinity() const
- {
- return traits_type::is_neg_inf(days_);
- }
-
- BOOST_CXX14_CONSTEXPR special_values as_special() const
- {
- return traits_type::to_special(days_);
- }
- BOOST_CXX14_CONSTEXPR duration_type operator-(const date_type& d) const
- {
- if (!this->is_special() && !d.is_special())
- {
-
-
- typedef typename duration_type::duration_rep_type duration_rep_type;
- return duration_type(static_cast< duration_rep_type >(days_) - static_cast< duration_rep_type >(d.days_));
- }
- else
- {
-
- date_rep_type val = date_rep_type(days_) - date_rep_type(d.days_);
- return duration_type(val.as_special());
- }
- }
- BOOST_CXX14_CONSTEXPR date_type operator-(const duration_type& dd) const
- {
- if(dd.is_special())
- {
- return date_type(date_rep_type(days_) - dd.get_rep());
- }
- return date_type(date_rep_type(days_) - static_cast<date_int_type>(dd.days()));
- }
- BOOST_CXX14_CONSTEXPR date_type operator-=(const duration_type& dd)
- {
- *this = *this - dd;
- return date_type(days_);
- }
- BOOST_CONSTEXPR date_rep_type day_count() const
- {
- return days_;
- }
-
- BOOST_CXX14_CONSTEXPR date_type operator+(const duration_type& dd) const
- {
- if(dd.is_special())
- {
- return date_type(date_rep_type(days_) + dd.get_rep());
- }
- return date_type(date_rep_type(days_) + static_cast<date_int_type>(dd.days()));
- }
- BOOST_CXX14_CONSTEXPR date_type operator+=(const duration_type& dd)
- {
- *this = *this + dd;
- return date_type(days_);
- }
-
- protected:
-
- BOOST_CONSTEXPR explicit date(date_int_type days) : days_(days) {}
- BOOST_CXX14_CONSTEXPR explicit date(date_rep_type days) : days_(days.as_number()) {}
- date_int_type days_;
- };
- } }
- #endif
|