|
Boost Users : |
From: Guido Spahn (gspahn_at_[hidden])
Date: 2005-08-22 04:26:12
Hello,
when adding a negative number of months to a date(y, m, d), an exception
"Month number is out of range 1..12" is raised if the resulting month m2
belongs to a year y2 < y and m2 > m. For example
date(2005, Jan, 1) + months(-1) fails
date(2005, Feb, 1) + months(-1) doesn't fail
date(2005, Feb, 1) + months(-2) fails
date(2005, Feb, 1) + months(-12) doesn't fail
date(2005, Feb, 1) + months(-13) doesn't fail
date(2005, Feb, 1) + months(-14) fails
I checked it only with release 1.33 using the appended code. There is no
problem adding or substracting any positive number of months.
Hopefully I didn't miss this topic in the mailing list archive. Thanks in
advance,
Guido
#include <boost/date_time/gregorian/gregorian.hpp>
int
main()
{
using namespace boost::gregorian;
date d(2005, May, 1);
for (long m = 0; m >= -40; --m)
{
try
{
std::cerr << d << " + (" << m << "): ";
std::cerr << d + months(m) << std::endl;
}
catch (std::exception& e)
{
std::cerr << "FAILED: " << e.what() << std::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