Boost logo

Boost Users :

From: __PPS__ (i-love-spam_at_[hidden])
Date: 2005-10-24 11:51:20


Jeff Garland wrote:

>>Are there better conversion functions from ISO date format (calendar,
>> ordinal, week dates) in basic and/or extended format? Should
>>conversion from invalid iso date like "20050231" fail or produce
>>same results as date(2005,02,31). (I know that it produces the same
>>results, but is it right to convert invalid iso date representation
>>to valid date?)
>
>
> In 1.33 the following code produces 2 exceptions:
>
> try {
> std::string ds("20050231");
> date d = from_undelimited_string(ds);
> std::cout << d << std::endl;
> }
> catch(bad_day_of_month& e) {
> std::cout << "exception: " << e.what() << std::endl;
> }
>
> try {
> date d(2005,02,31);
> std::cout << d << std::endl;
> }
> catch(bad_day_of_month& e) {
> std::cout << "exception: " << e.what() << std::endl;
> }

Ok, I was wrong that they produce the same results, but I was wrong
cause I didn't expect that date(2005,02,31) checks date correctness
similar to from_undelimited_string("20050231"); which does not. Did you
try to run these two examples? I got this output (v 1.33):
2005-Mar-03
exception: Day of month is not valid for year

>>Another thing I noted, some conversion functions accept const
>>std::string &, but most of them accept plain std::string, isn't
>>better to convert all of them to constant references???
>
>
> Sure unless they copy the string anyway, which I don't think they do.

from_undelimited_string(std::string) does exactly the same as
date_from_iso_string(const std::string &)

>
>>If anybody interested, I wrote such function that accepts iso date
>>string in any of the above mentioned 6 combinations and returns
>>date. It runs 90-100 times faster than equivalent
>>date_from_iso_string from boost. And yes, it does make sure that
>>"20050229" fails
>
>
> As I said above, contributions always welcome.

this is my code that converts iso date string to gregorian::date:
http://tinyurl.com/cvqhb

Waiting for comments...


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