Refactor wxGridCellDateRenderer::Parse() to make it reusable

No real changes, just create TryParseDate() helper in order to allow
reusing it from wxGridCellDateEditor too in the upcoming commit.
This commit is contained in:
Vadim Zeitlin
2020-11-03 02:50:31 +01:00
parent eda11b8755
commit 56ec476a3a
2 changed files with 33 additions and 10 deletions

View File

@@ -76,6 +76,23 @@ void wxGridCellRenderer::Draw(wxGrid& grid,
#if wxUSE_DATETIME
bool
wxGridPrivate::TryParseDate(wxDateTime& result,
const wxString& text,
const wxString& format)
{
wxString::const_iterator end;
// Try parsing using the same format we use for output first.
if ( result.ParseFormat(text, format, &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();
}
// Enables a grid cell to display a formatted date
wxGridCellDateRenderer::wxGridCellDateRenderer(const wxString& outformat)
@@ -131,16 +148,7 @@ 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();
return wxGridPrivate::TryParseDate(result, text, m_oformat);
}
void wxGridCellDateRenderer::Draw(wxGrid& grid,