wxWidgets / wxWidgets

Cross-Platform C++ GUI Library
https://www.wxwidgets.org/
6k stars 1.75k forks source link

Calendar reports invalid date format when using ca_ES locale #24533

Closed sethhillbrand closed 3 months ago

sethhillbrand commented 3 months ago

Description

Bug description:

Wx does not appear to recognize dates for Linux systems when running in Catalan locale (ca_ES.UTF-8)

Expected vs observed behaviour:

Selecting a calendar date in the wx calendar sample fails verification. Note that this is not only when typing the date in but also when selecting the calendar date using the widget.

image

To Reproduce:

Steps to reproduce the behaviour, please make them as detailed as possible. For example:

  1. Set system locale to ca_ES.UTF8
  2. Run wxWidgets Calendar sample application
  3. Choose a date from the calendar
  4. See error

Platform and version information

See also https://gitlab.com/kicad/code/kicad/-/issues/17992 . Apparently affects Czech language as well but not French

vadz commented 3 months ago

Thanks, I see it with both 3.2 and master, will debug/fix a.s.a.p.

vadz commented 3 months ago

OK, I have a fix but I think I need to improve/generalize it before making the PR.

The problem is that cs_ES, as well as cs_CZ and a bunch of Indian and Nepal locales use %-d and/or %-m in their d_fmt, i.e. a non-standard (documented as a glibc extension in BSD (!) strftime(1) and I couldn't find it documented in Open Group specifications) format specifier not recognized by wxDateTime. It's easy enough to add support for it (and I did it), but there are other specifiers we still don't support, at least %Od, %Om and %Oy used in Iranian and Burmese locales. It's probably worth adding support for those as well, but even we do this, the problem might still arise in the future with some new/unknown specifiers, so I'd like to change the generic wxDatePickerCtrl to always allow the user to enter the date in ISO 8601 format as a fallback to ensure that even the users of rare locales can use it.

Please let me know if anybody has any comments about this.

sethhillbrand commented 3 months ago

That sounds like a good plan. Thanks!

vadz commented 3 months ago

The PR above fixes parsing dates in ca_ES and cz_CZ and adds fallback to ISO 8601 if the locale date format can't be used, as proposed, but doesn't implement support for %E* and %O* as this is much more involved: for the former, we need to use the alternative day/month forms (which, I think, correspond to the wxDateTime::NameForm values, but I haven't actually tested this) and for the latter we need to use the alternative digits (e.g. U+06F0 instead of 0 etc).

So parsing dates in the following locales, available on my Debian system, still doesn't work correctly:

But with ISO 8601 it's a bit less catastrophic as before.