I'm also encountering this problem when trying to sort elements in a grid view by their date. When I output the day, month, and year determined by ParseDate to the console, I'm further surprised to find that the month is off by one each time.
Here are some examples ('date string' is the input for ParseDate as dd.mm.yyyy):
Is there a solution or workaround for this?
OS: Kubuntu 25.10
wxGtk: 3.2.8
Localization: de_DE.UTF-8
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.![]()
I'm also encountering this problem when trying to sort elements in a grid view by their date. When I output the day, month, and year determined by ParseDate to the console, I'm further surprised to find that the month is off by one each time.
Here are some examples ('date string' is the input for ParseDate as dd.mm.yyyy):
* date string: 02.01.2026 ; day: 1 ; month: 1 ; year: 2026 * date string: 01.02.2026 ; day: 2 ; month: 0 ; year: 2026 * date string: 26.12.2025 ; day: 26 ; month: 11 ; year: 2025 * date string: 22.03.2026 ; day: 22 ; month: 2 ; year: 2026
Is there a solution or workaround for this?
OS: Kubuntu 25.10 wxGtk: 3.2.8 Localization: de_DE.UTF-8
Are you aware that wxDateTime()::GetMonth() returns the month as wxDateTime::Month enum, which for some reason counterintuitively starts with 0 and not 1, i.e., January is 0 and December 11? So, this code (on Windows 11)
#include <wx/wx.h> #include <wx/intl.h> class MyApp : public wxApp { bool OnInit() override { const wxLocale locale(wxLANGUAGE_GERMAN); if ( !locale.IsOk() ) wxLogError("Failed to initialize locale to wxLANGUAGE_CZECH."); const wxString dateStr("02.01.2026"); wxDateTime dt; if ( !dt.ParseDate(dateStr) ) wxLogError("Failed to parse date '%s'.", dateStr); wxLogDebug("Locale name: '%s', date '%s' parsed as: DD.MM.YYYY='%02d.%02d.%d', ISO='%s'", locale.GetName(), dateStr, dt.GetDay(), dt.GetMonth(), dt.GetYear(), dt.FormatISODate()); return false; } }; wxIMPLEMENT_APP(MyApp);
correctly outputs (notice that February in wxDateTime::Month is 1)
Locale name: 'de_DE', date '02.01.2026' parsed as: DD.MM.YYYY='01.01.2026', ISO='2026-02-01'
In your examples, I see problems with the first two dates, where the day and month are detected incorrectly (i.e., swapped). My guess would be it is because in the later two dates the day is too large to be a month so the day and month are assigned correctly. Are you sure your application locale is set to German?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.![]()
Yes, for any code knowing the format ParseFormat() should be used, of course.
I think ParseDate() could still be modified to prefer the same d/m/y order as the current locale but I'm not really sure if it's worth it, to be honest.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.![]()
Ah, right. wxDateTime()::GetMonth() returns an enumeration. However, this only affects the debug output, which I used to better understand how wxDateTime()::ParseDate() interprets the day and month.
The open-source application is used by users in various countries and therefore with different localization settings. The localization 'de_DE.UTF-8' was used for testing purposes only, among other settings. This revealed that the day and month determined by wxDateTime()::ParseDate() are sometimes reversed.
How can wxDateTime()::ParseFormat() be used while taking localization into account? The format parameter would need to be selected based on the localization settings.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.![]()
How can
wxDateTime()::ParseFormat()be used while taking localization into account? Theformatparameter would need to be selected based on the localization settings.
I have no idea how to query the application wxLocale for the short date format. static wxLocale::GetInfo(wxLOCALE_SHORT_DATE_FMT) seems to return the system one, which may not be the same as the application one.
But it seems it could be done with wxUILocale, this for "02.01.2026" (on Windows)
#include <wx/wx.h> #include <wx/intl.h> #include <wx/uilocale.h>
class MyApp : public wxApp { bool OnInit() override { const wxLocale locale
(wxLANGUAGE_GERMAN);
const wxUILocale uiLocale = wxUILocale::FromTag("de-DE");
if ( !locale.IsOk() || !uiLocale.IsSupported())
{
wxLogError("Failed to initialize locale.");
return false;
}
const wxString dateStr("02.01.2026");
const wxString uiLocaleShortDateFmt = uiLocale.GetInfo(wxLOCALE_SHORT_DATE_FMT);
wxDateTime dt;
wxLogDebug("wxLocale name is '%s', wxUILocale name is '%s', wxUILocale short date format is '%s'.",
locale.GetName(), uiLocale.GetName(), uiLocaleShortDateFmt);
if ( dt.ParseFormat(dateStr, uiLocaleShortDateFmt) )
{
wxLogDebug("Date '%s' parsed as: wxLocale formatted='%s', ISO='%s', English month='%s'.",
dateStr, dt.FormatDate(), dt.FormatISODate(), dt.GetEnglishMonthName(dt.GetMonth()));
}
else
{
wxLogError("Failed to parse date '%s'."
, dateStr);
}
return false;
}
}; wxIMPLEMENT_APP(MyApp);correctly outputs
wxLocale name is 'de_DE', wxUILocale name is 'de-DE', wxUILocale short date format is '%d.%m.%Y'.
Date '02.01.2026' parsed as: wxLocale formatted='02.01.2026', ISO='2026-01-02', English month='January'.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.![]()