wxWidgets 2.6.3 bug in wxDateTime::ParseDate Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
mbluett
In need of some credit
In need of some credit
Posts: 3
Joined: Tue Jul 25, 2006 10:45 pm

wxWidgets 2.6.3 bug in wxDateTime::ParseDate

Post by mbluett » Sun Jul 30, 2006 8:10 pm

There seems to be a bug in determining the components of a date in wxDateTime::ParseDate.

If I use 0005-10-04 as input (wxChar *date), the routine at the following step determines that 0005 is a month which is incorrect (it is a year). That should be obvious because it has 4 digits (YYYY-MM-DD is the format that wxSQLite3 uses to store dates).

if ( !haveMon && val > 0 && val <= 12 )
{
// assume it is month
isMonth = true;
}

As there is no way for the evaluation "val > 0 && val <= 12" to determine precisely that we are talking about a month, day or year this code will not work.

If the alogrithm saw 4 digits then it could assume that it was a year. If it sees 2 digits, is it a month or a day? There is no way of telling unless the digits are greater than 12. But, any digits from 1-12 could either be a month or a day. So if you have 0005-1-2, is the 1 the month or is the 2 the month?

I think the way to fix this is not to guess as this algorithm does. There is no point in even trying because if the format is available (which it is from wxSQLite) this guessing is not required and in fact the only reason (at least that I can see) to Parse at all would be to re-arrange the formatting.

I'm not sure I know what the intention of the ParseDate method was, but it does seem to fill in m_time. So, if the purpose of this routine is to fill in m_time then it should require a format specifier as a parameter to ParseDate.

Comments?

Peterj
Knows some wx things
Knows some wx things
Posts: 38
Joined: Mon Nov 14, 2005 6:48 pm
Location: Australia

Post by Peterj » Sun Jul 30, 2006 8:44 pm

Yes you're right. There are bugs in wxDateTime that I believe have been fixed in the next version.

You can get around the problem using ParseFormat(wxStringToParse,"%Y-%m-%d").
Likewise you are also likely to strike problems with FormatDate - just use Format instead and specify the format.

The other interesting one is that a date like "00/00/0000" isn't returned as in invalid date, but rather translated to be "01/01/1970".

I hope this helps.

Peter
Using Win XP, Dev C++ 4.9.9.2 wx-beta 6.9

mbluett
In need of some credit
In need of some credit
Posts: 3
Joined: Tue Jul 25, 2006 10:45 pm

Post by mbluett » Sun Jul 30, 2006 9:35 pm

Thanks for the response Peter J.

I had already changed my code to use ParseFormat and works properly now.

Incidentally, the latest MSW build that has todays date shows that the ParseDate method is still broken.

Post Reply