File indexing completed on 2025-02-25 09:37:27
0001 #ifndef GREG_DATE_HPP___
0002 #define GREG_DATE_HPP___
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <boost/throw_exception.hpp>
0013 #include <boost/date_time/compiler_config.hpp>
0014 #include <boost/date_time/date.hpp>
0015 #include <boost/date_time/special_defs.hpp>
0016 #include <boost/date_time/gregorian/greg_calendar.hpp>
0017 #include <boost/date_time/gregorian/greg_duration.hpp>
0018
0019 namespace boost {
0020 namespace gregorian {
0021
0022
0023 using date_time::special_values;
0024 using date_time::not_special;
0025 using date_time::neg_infin;
0026 using date_time::pos_infin;
0027 using date_time::not_a_date_time;
0028 using date_time::max_date_time;
0029 using date_time::min_date_time;
0030
0031
0032
0033
0034
0035
0036
0037
0038 class BOOST_SYMBOL_VISIBLE date : public date_time::date<date, gregorian_calendar, date_duration>
0039 {
0040 public:
0041 typedef gregorian_calendar::year_type year_type;
0042 typedef gregorian_calendar::month_type month_type;
0043 typedef gregorian_calendar::day_type day_type;
0044 typedef gregorian_calendar::day_of_year_type day_of_year_type;
0045 typedef gregorian_calendar::ymd_type ymd_type;
0046 typedef gregorian_calendar::date_rep_type date_rep_type;
0047 typedef gregorian_calendar::date_int_type date_int_type;
0048 typedef date_duration duration_type;
0049 #if !defined(DATE_TIME_NO_DEFAULT_CONSTRUCTOR)
0050
0051 BOOST_CXX14_CONSTEXPR date():
0052 date_time::date<date, gregorian_calendar, date_duration>(date_rep_type::from_special(not_a_date_time))
0053 {}
0054 #endif
0055
0056 BOOST_CXX14_CONSTEXPR date(year_type y, month_type m, day_type d)
0057 : date_time::date<date, gregorian_calendar, date_duration>(y, m, d)
0058 {
0059 if (gregorian_calendar::end_of_month_day(y, m) < d) {
0060 boost::throw_exception(bad_day_of_month(std::string("Day of month is not valid for year")));
0061 }
0062 }
0063
0064 BOOST_CXX14_CONSTEXPR explicit date(const ymd_type& ymd)
0065 : date_time::date<date, gregorian_calendar, date_duration>(ymd)
0066 {}
0067
0068 BOOST_CXX14_CONSTEXPR explicit date(const date_int_type& rhs):
0069 date_time::date<date,gregorian_calendar, date_duration>(rhs)
0070 {}
0071
0072 BOOST_CXX14_CONSTEXPR explicit date(date_rep_type rhs):
0073 date_time::date<date,gregorian_calendar, date_duration>(rhs)
0074 {}
0075
0076 BOOST_CXX14_CONSTEXPR explicit date(special_values sv):
0077 date_time::date<date, gregorian_calendar, date_duration>(from_special_adjusted(sv))
0078 {}
0079
0080 BOOST_CXX14_CONSTEXPR date_int_type julian_day() const
0081 {
0082 ymd_type ymd = year_month_day();
0083 return gregorian_calendar::julian_day_number(ymd);
0084 }
0085
0086 BOOST_CXX14_CONSTEXPR day_of_year_type day_of_year() const
0087 {
0088 date start_of_year(year(), 1, 1);
0089 unsigned short doy = static_cast<unsigned short>((*this-start_of_year).days() + 1);
0090 return day_of_year_type(doy);
0091 }
0092
0093 BOOST_CXX14_CONSTEXPR date_int_type modjulian_day() const
0094 {
0095 ymd_type ymd = year_month_day();
0096 return gregorian_calendar::modjulian_day_number(ymd);
0097 }
0098
0099 BOOST_CXX14_CONSTEXPR int week_number() const
0100 {
0101 ymd_type ymd = year_month_day();
0102 return gregorian_calendar::week_number(ymd);
0103 }
0104
0105 BOOST_CXX14_CONSTEXPR date_int_type day_number() const
0106 {
0107 return days_;
0108 }
0109
0110 BOOST_CXX14_CONSTEXPR date end_of_month() const
0111 {
0112 ymd_type ymd = year_month_day();
0113 unsigned short eom_day = gregorian_calendar::end_of_month_day(ymd.year, ymd.month);
0114 return date(ymd.year, ymd.month, eom_day);
0115 }
0116
0117 friend BOOST_CXX14_CONSTEXPR
0118 bool operator==(const date& lhs, const date& rhs);
0119
0120 private:
0121
0122 BOOST_CXX14_CONSTEXPR date_rep_type from_special_adjusted(special_values sv)
0123 {
0124 switch (sv)
0125 {
0126 case min_date_time: return gregorian_calendar::day_number(ymd_type(1400, 1, 1));
0127 case max_date_time: return gregorian_calendar::day_number(ymd_type(9999, 12, 31));
0128 default: return date_rep_type::from_special(sv);
0129 }
0130 }
0131 };
0132
0133 inline BOOST_CXX14_CONSTEXPR
0134 bool operator==(const date& lhs, const date& rhs)
0135 {
0136 return lhs.days_ == rhs.days_;
0137 }
0138
0139
0140 } }
0141
0142
0143
0144 #endif