mate-desktop / mate-panel

MATE panel
https://mate-desktop.org
GNU General Public License v2.0
184 stars 118 forks source link

Clock applet: 12-hour time format broken with musl libc #1451

Open alterae opened 1 month ago

alterae commented 1 month ago

Expected behaviour

Setting the time format option for the clock applet to twelve-hour display should display the time in a twelve-hour format.

Actual behaviour

Setting the time format option for the clock applet to twelve-hour display causes the time string to display as ???.

Steps to reproduce the behaviour

  1. Right click the clock applet.
  2. Open the preferences menu.
  3. Select twelve-hour time.

MATE general version

mate 1.26.0_1

Package version

mate-panel 1.28.2_1

Linux Distribution

Void (with musl libc musl 1.1.24_21)

Link to bugreport of your Distribution (requirement)

https://github.com/void-linux/void-packages/issues/52494

alterae commented 1 month ago

Additional information:

I am able to work around the issue by setting a custom time format string through dconf. Strings containing the %p specifier (uppercase AM/PM) work as expected, while strings containing %P (lowercase am/pm, and a GNU extension) display as ???.

sgn commented 1 month ago

No, it isn't %P, it's %l, we could use another extension %_I which is supported by glibc, musl, and BSD.

https://github.com/mate-desktop/mate-panel/blob/1de955b0b3a80cbc1bd840bad312f8ad3f0ae99b/applets/clock/clock.c#L461

A possible patch is:

--- a/applets/clock/clock-location-tile.c
+++ b/applets/clock/clock-location-tile.c
@@ -434,7 +434,7 @@ format_time (struct tm   *now,
                          * weekday differs from the weekday at the location
                          * (the %A expands to the weekday). The %p expands to
                          * am/pm. */
-                        format = _("%l:%M <small>%p (%A)</small>");
+                        format = _("%_I:%M <small>%p (%A)</small>");
                 }
                 else {
                         /* Translators: This is a strftime format string.
@@ -451,7 +451,7 @@ format_time (struct tm   *now,
                          * It is used to display the time in 12-hours format
                          * (eg, like in the US: 8:10 am). The %p expands to
                          * am/pm. */
-                        format = _("%l:%M <small>%p</small>");
+                        format = _("%_I:%M <small>%p</small>");
                 }
                 else {
                         /* Translators: This is a strftime format string.
@@ -497,7 +497,7 @@ convert_time_to_str (time_t now, ClockFo
                  * It is used to display the time in 12-hours format (eg, like
                  * in the US: 8:10 am). The %p expands to am/pm.
                  */
-                format = _("%l:%M %p");
+                format = _("%_I:%M %p");
         }
         else {
                 /* Translators: This is a strftime format string.
--- a/applets/clock/clock.c
+++ b/applets/clock/clock.c
@@ -458,7 +458,7 @@ get_updated_timeformat (ClockData *cd)
                 /* Translators: This is a strftime format string.
                  * It is used to display the time in 12-hours format (eg, like
                  * in the US: 8:10 am). The %p expands to am/pm. */
-                time_format = cd->showseconds ? _("%l:%M:%S %p") : _("%l:%M %p");
+                time_format = cd->showseconds ? _("%_I:%M:%S %p") : _("%_I:%M %p");
         else
                 /* Translators: This is a strftime format string.
                  * It is used to display the time in 24-hours format (eg, like