[date_time] problem adding negative number of months
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
On Mon, 22 Aug 2005 11:26:12 +0200, Guido Spahn wrote:
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
This certainly isn't the correct behavior. Thank you for bringing it to our attention. Bart
On Mon, 22 Aug 2005 11:26:12 +0200, Guido Spahn wrote
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.
This is fixed in CVS now. You can fix your 1.33 distribution by downloading wrapping_int.hpp version 1.7 from http://cvs.sourceforge.net/viewcvs.py/boost/boost/boost/date_time/wrapping_int.hpp?rev=1.6&view=log (might take a little while to catch up). Thx for the report. Jeff
On Mon, 22 Aug 2005 11:26:12 +0200, Guido Spahn wrote
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,
Just in the way of a final followup to this message, I've checked a fix into 1.33.1 for this problem. It's actually been fixed in the mainline for awhile now. As you pointed out, this problem was particular to using negative months. If you want to just patch your 1.33 version you just need to pick up the latest version of boost/date_time/wrapping_int.hpp. Thx again for the report. Jeff
participants (3)
-
Bart
-
Guido Spahn
-
Jeff Garland