Chris@16: #ifndef GREG_DATE_HPP___ Chris@16: #define GREG_DATE_HPP___ Chris@16: Chris@16: /* Copyright (c) 2002,2003 CrystalClear Software, Inc. Chris@16: * Use, modification and distribution is subject to the Chris@16: * Boost Software License, Version 1.0. (See accompanying Chris@16: * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) Chris@16: * Author: Jeff Garland Chris@101: * $Date$ Chris@16: */ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace gregorian { Chris@16: Chris@16: //bring special enum values into the namespace Chris@16: using date_time::special_values; Chris@16: using date_time::not_special; Chris@16: using date_time::neg_infin; Chris@16: using date_time::pos_infin; Chris@16: using date_time::not_a_date_time; Chris@16: using date_time::max_date_time; Chris@16: using date_time::min_date_time; Chris@16: Chris@16: //! A date type based on gregorian_calendar Chris@16: /*! This class is the primary interface for programming with Chris@16: greogorian dates. The is a lightweight type that can be Chris@16: freely passed by value. All comparison operators are Chris@16: supported. Chris@16: \ingroup date_basics Chris@16: */ Chris@16: class date : public date_time::date Chris@16: { Chris@16: public: Chris@16: typedef gregorian_calendar::year_type year_type; Chris@16: typedef gregorian_calendar::month_type month_type; Chris@16: typedef gregorian_calendar::day_type day_type; Chris@16: typedef gregorian_calendar::day_of_year_type day_of_year_type; Chris@16: typedef gregorian_calendar::ymd_type ymd_type; Chris@16: typedef gregorian_calendar::date_rep_type date_rep_type; Chris@16: typedef gregorian_calendar::date_int_type date_int_type; Chris@16: typedef date_duration duration_type; Chris@16: #if !defined(DATE_TIME_NO_DEFAULT_CONSTRUCTOR) Chris@16: //! Default constructor constructs with not_a_date_time Chris@16: date(): Chris@16: date_time::date(date_rep_type::from_special(not_a_date_time)) Chris@16: {} Chris@16: #endif // DATE_TIME_NO_DEFAULT_CONSTRUCTOR Chris@16: //! Main constructor with year, month, day Chris@16: date(year_type y, month_type m, day_type d) Chris@16: : date_time::date(y, m, d) Chris@16: { Chris@16: if (gregorian_calendar::end_of_month_day(y, m) < d) { Chris@16: boost::throw_exception(bad_day_of_month(std::string("Day of month is not valid for year"))); Chris@16: } Chris@16: } Chris@16: //! Constructor from a ymd_type structure Chris@16: explicit date(const ymd_type& ymd) Chris@16: : date_time::date(ymd) Chris@16: {} Chris@16: //! Needed copy constructor Chris@16: explicit date(const date_int_type& rhs): Chris@16: date_time::date(rhs) Chris@16: {} Chris@16: //! Needed copy constructor Chris@16: explicit date(date_rep_type rhs): Chris@16: date_time::date(rhs) Chris@16: {} Chris@16: //! Constructor for infinities, not a date, max and min date Chris@16: explicit date(special_values sv): Chris@16: date_time::date(date_rep_type::from_special(sv)) Chris@16: { Chris@16: if (sv == min_date_time) Chris@16: { Chris@16: *this = date(1400, 1, 1); Chris@16: } Chris@16: if (sv == max_date_time) Chris@16: { Chris@16: *this = date(9999, 12, 31); Chris@16: } Chris@16: Chris@16: } Chris@16: //!Return the Julian Day number for the date. Chris@16: date_int_type julian_day() const Chris@16: { Chris@16: ymd_type ymd = year_month_day(); Chris@16: return gregorian_calendar::julian_day_number(ymd); Chris@16: } Chris@16: //!Return the day of year 1..365 or 1..366 (for leap year) Chris@16: day_of_year_type day_of_year() const Chris@16: { Chris@16: date start_of_year(year(), 1, 1); Chris@16: unsigned short doy = static_cast((*this-start_of_year).days() + 1); Chris@16: return day_of_year_type(doy); Chris@16: } Chris@16: //!Return the Modified Julian Day number for the date. Chris@16: date_int_type modjulian_day() const Chris@16: { Chris@16: ymd_type ymd = year_month_day(); Chris@16: return gregorian_calendar::modjulian_day_number(ymd); Chris@16: } Chris@16: //!Return the iso 8601 week number 1..53 Chris@16: int week_number() const Chris@16: { Chris@16: ymd_type ymd = year_month_day(); Chris@16: return gregorian_calendar::week_number(ymd); Chris@16: } Chris@16: //! Return the day number from the calendar Chris@16: date_int_type day_number() const Chris@16: { Chris@16: return days_; Chris@16: } Chris@16: //! Return the last day of the current month Chris@16: date end_of_month() const Chris@16: { Chris@16: ymd_type ymd = year_month_day(); Chris@16: short eom_day = gregorian_calendar::end_of_month_day(ymd.year, ymd.month); Chris@16: return date(ymd.year, ymd.month, eom_day); Chris@16: } Chris@16: Chris@16: private: Chris@16: Chris@16: }; Chris@16: Chris@16: Chris@16: Chris@16: } } //namespace gregorian Chris@16: Chris@16: Chris@16: Chris@16: #endif