Date-Time gregorian::date construction question
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
On Wed, 26 Jan 2005 17:20:40 +0100, Wolfgang Fertsak wrote
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?
That would be a bug. Note that the only invalid dates that will do this are non-leap year Feb 29 dates. That is, strDate("2005-02-30") will throw the exception. I'm afraid I can't check in a fix just at the moment, but it's a one line fix if you want to patch it: Change line 146 of boost/date_time/date_parsing.hpp from < return date_type(ymd); to
return date_type(ymd.year, ymd.month, ymd.day);
With this change you'll get the exception for the feb 29th's as well. Thanks for the report. Jeff
That would be a bug. Note that the only invalid dates that will do this are non-leap year Feb 29 dates. That is, strDate("2005-02-30") will throw the exception. strDate("2005-02-30") doesn't throw an exception either (I used MSVC 7.1, Win2000), but the fix in line 146 (in boost 1.32 release it is line
Jeff Garland schrieb: 141) also corrects that. Wolfgang
On Thu, 27 Jan 2005 10:52:57 +0100, Wolfgang Fertsak wrote
Jeff Garland schrieb:
That would be a bug. Note that the only invalid dates that will do this are non-leap year Feb 29 dates. That is, strDate("2005-02-30") will throw the exception. strDate("2005-02-30") doesn't throw an exception either (I used MSVC
7.1, Win2000), but the fix in line 146 (in boost 1.32 release it is line 141) also corrects that.
Wolfgang
Hmm, I tested it on gcc 3.2 before I wrote that. Are you sure you remembered to remove the first date construction from the program before you tested it? That is, if you left in: date Date1(2005,2,31); you never actually execute the code below it since the exception fires at that point. Well anyway, it's fixed now.... Jeff
Jeff Garland schrieb:
Hmm, I tested it on gcc 3.2 before I wrote that. Are you sure you remembered to remove the first date construction from the program before you tested it? Yes! I tried several more dates: 2005-02-31 - no exception 2005-11-31 - no exception 2005-02-32 - exeption is thrown "Day of month value is out of range 1..31" Looks like the day of month is (well - was) only checked for being between 1-31. Stefan already added the fix and a test case.
Kind regards, Wolfgang
sorry if this has been answered before, I'm new on the list. are there any resources explaining _efficient_ use of MPL? because I've written a few metafunctions which determine the virtual bases of a class and write them to a map, which you can use for not calling virtual bases twice. and it worked but with larger hierarchy structures I cancelled GCC after 5 minutes and 600 MB of memory. thanks,
"Stefan Strasser"
are there any resources explaining _efficient_ use of MPL?
See http://www.boost-consulting.com/metaprogramming-book.html, appendix C.
because I've written a few metafunctions which determine the virtual bases of a class and write them to a map, which you can use for not calling virtual bases twice. and it worked but with larger hierarchy structures I cancelled GCC after 5 minutes and 600 MB of memory.
If you wrote everything correctly in terms of algorithm complexity, and it is still slow with GCC, see if you use metafunction forwarding, and try to remove it. It is a known problem that GCC is very slow with metafunction forwarding. HTH, Arkadiy
participants (5)
-
Arkadiy Vertleyb
-
Jeff Garland
-
Stefan Slapeta
-
Stefan Strasser
-
Wolfgang Fertsak