calendar-Use-the-new-OB-format-if-supported.patch 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. From: Rafal Luzynski <digitalfreak@lingonborough.com>
  2. Date: Sat, 10 Feb 2018 14:07:56 +0100
  3. Subject: calendar: Use the new "%OB" format if supported
  4. Due to the recent changes introduced in glibc 2.27 "%OB" is the
  5. correct format to obtain a month name as used in the calendar
  6. header. The same rule has been working in BSD family (including
  7. OS X) since 1990s. This simple hack checks whether "%OB" is supported
  8. at runtime and uses it if it is, falls back to the old "%B" otherwise.
  9. Bug: #9
  10. Origin: upstream, 2.24.33, commit:2ea743ab466703091a44a74e1a4ac7db983c0bca
  11. ---
  12. gtk/gtkcalendar.c | 19 +++++++++++++++++--
  13. 1 file changed, 17 insertions(+), 2 deletions(-)
  14. diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
  15. index 2dd68d6..28baba1 100644
  16. --- a/gtk/gtkcalendar.c
  17. +++ b/gtk/gtkcalendar.c
  18. @@ -689,6 +689,7 @@ gtk_calendar_init (GtkCalendar *calendar)
  19. #ifdef G_OS_WIN32
  20. wchar_t wbuffer[100];
  21. #else
  22. + static const char *month_format = NULL;
  23. char buffer[255];
  24. time_t tmp_time;
  25. #endif
  26. @@ -714,7 +715,7 @@ gtk_calendar_init (GtkCalendar *calendar)
  27. {
  28. #ifndef G_OS_WIN32
  29. tmp_time= (i+3)*86400;
  30. - strftime ( buffer, sizeof (buffer), "%a", gmtime (&tmp_time));
  31. + strftime (buffer, sizeof (buffer), "%a", gmtime (&tmp_time));
  32. default_abbreviated_dayname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
  33. #else
  34. if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SABBREVDAYNAME1 + (i+6)%7,
  35. @@ -730,7 +731,21 @@ gtk_calendar_init (GtkCalendar *calendar)
  36. {
  37. #ifndef G_OS_WIN32
  38. tmp_time=i*2764800;
  39. - strftime ( buffer, sizeof (buffer), "%B", gmtime (&tmp_time));
  40. + if (G_UNLIKELY (month_format == NULL))
  41. + {
  42. + buffer[0] = '\0';
  43. + month_format = "%OB";
  44. + strftime (buffer, sizeof (buffer), month_format, gmtime (&tmp_time));
  45. + /* "%OB" is not supported in Linux with glibc < 2.27 */
  46. + if (!strcmp (buffer, "%OB") || !strcmp (buffer, "OB") || !strcmp (buffer, ""))
  47. + {
  48. + month_format = "%B";
  49. + strftime (buffer, sizeof (buffer), month_format, gmtime (&tmp_time));
  50. + }
  51. + }
  52. + else
  53. + strftime (buffer, sizeof (buffer), month_format, gmtime (&tmp_time));
  54. +
  55. default_monthname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
  56. #else
  57. if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SMONTHNAME1 + i,