Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.

Class template partial_date

boost::date_time::partial_date — Generates a date by applying the year to the given month and day.


template<typename date_type> 
class partial_date
  :  : public boost::date_time::year_based_generator< date_type >
// 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);

// public member functions
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 construct/copy/destruct

  1. partial_date(day_type d, month_type m);
  2. partial_date(duration_rep days);

    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 functions

  1. date_type get_date(year_type y) const;

    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
  2. date_type operator()(year_type y) const;
  3. bool operator==(const partial_date & rhs) const;
  4. bool operator<(const partial_date & rhs) const;
  5. month_type month() const;
  6. day_type day() const;
  7. virtual std::string to_string() const;

    Returns string formatted with up to 3 digits: Jan-01 == "0" Feb-29 == "58" Dec-31 == "365"

Copyright 2001-2005 CrystalClear Software, Inc