Boost logo

Boost Users :

From: Wolfgang Fertsak (wolfgang.fertsak_at_[hidden])
Date: 2005-01-26 11:20:40


If a date object is constructed from an invalid date(e.g. Feb 29th,
2005) and the values are specified in the constructor, an exception is
thrown.
If the object is constructed from a string representation with
from_string(), no exception is thrown and the object has the next valid
date (in this case Mar 1st, 2005).

Is this a bug or a feature?

Best regards,
Wolfgang

#include <iostream>
#include <boost/date_time/gregorian/gregorian.hpp>
using namespace boost::gregorian;
using namespace std;

int main()
{
     try {
         // throws exception
         date Date1(2005,2,29);

         string strDate("2005-02-29");
         // throws no exception
         date Date2 = from_string(strDate);
         // output is 2005-03-01
         cout << to_iso_extended_string(Date2) << endl;
     }
     catch(std::exception&e) {
         cout << e.what() << endl;
     }
     return 0;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net