Use specified format in wxGridCellDateRenderer if possible
For the tables that store dates as strings, we must use the specified format for interpreting the table data, as otherwise we could confuse the user by showing it incorrectly: for example, if "%d.%m.%y" format is used, "01.03.02" should really mean 2002-03-01, but it was parsed as 0002-01-03 by ParseDate() which had no choice but to guess the order of data components.
This commit is contained in:
@@ -132,6 +132,14 @@ wxString wxGridCellDateRenderer::GetString(const wxGrid& grid, int row, int col)
|
||||
bool wxGridCellDateRenderer::Parse(const wxString& text, wxDateTime& result)
|
||||
{
|
||||
wxString::const_iterator end;
|
||||
|
||||
// Try parsing using the same format we use for output first.
|
||||
if ( result.ParseFormat(text, m_oformat, &end) && end == text.end() )
|
||||
return true;
|
||||
|
||||
// But fall back to free-form parsing, which notably allows us to parse
|
||||
// strings such as "today" or "tomorrow" which would be never accepted by
|
||||
// ParseFormat().
|
||||
return result.ParseDate(text, &end) && end == text.end();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user