...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::date_time::partial_date — Generates a date by applying the year to the given month and day.
// In header: <boost/date_time/date_generators.hpp> template<typename date_type> class partial_date : public boost::date_time::year_based_generator< date_type > { public: // types typedef date_type::calendar_type calendar_type; typedef calendar_type::day_type day_type; typedef calendar_type::month_type month_type; typedef calendar_type::year_type year_type; typedef date_type::duration_type duration_type; typedef duration_type::duration_rep duration_rep; // construct/copy/destruct partial_date(day_type, month_type); partial_date(duration_rep); // public member functions virtual date_type get_date(year_type) const; date_type operator()(year_type) const; bool operator==(const partial_date &) const; bool operator<(const partial_date &) const; month_type month() const; day_type day() const; virtual std::string to_string() const; };
Example usage:
partial_date pd(1, Jan); partial_date pd2(70); date d = pd.get_date(2002); //2002-Jan-01 date d2 = pd2.get_date(2002); //2002-Mar-10
partial_date
public
construct/copy/destructpartial_date(day_type d, month_type m);
partial_date(duration_rep days);Partial date created from number of days into year. Range 1-366.
Allowable values range from 1 to 366. 1=Jan1, 366=Dec31. If argument exceeds range, partial_date
will be created with closest in-range value. 60 will always be Feb29, if get_date() is called with a non-leap year an exception will be thrown
partial_date
public member functionsvirtual date_type get_date(year_type y) const;Return a concrete date when provided with a year specific year.
Will throw an 'invalid_argument' exception if a partial_date
object, instantiated with Feb-29, has get_date called with a non-leap year. Example:
partial_date pd(29, Feb); pd.get_date(2003); // throws invalid_argument exception pg.get_date(2000); // returns 2000-2-29
date_type operator()(year_type y) const;
bool operator==(const partial_date & rhs) const;
bool operator<(const partial_date & rhs) const;
month_type month() const;
day_type day() const;
virtual std::string to_string() const;Returns string suitable for use in POSIX time zone string.
Returns string formatted with up to 3 digits: Jan-01 == "0" Feb-29 == "58" Dec-31 == "365"