From eda11b8755aed36c89ce86ab6da0b293b0933ac0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 3 Nov 2020 02:37:02 +0100 Subject: [PATCH] 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. --- src/generic/gridctrl.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/generic/gridctrl.cpp b/src/generic/gridctrl.cpp index a82d8ea24f..38744e2ff3 100644 --- a/src/generic/gridctrl.cpp +++ b/src/generic/gridctrl.cpp @@ -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(); }