gdatetime: Use figure space for %e

Helps: #2655
This commit is contained in:
Maksym Hazevych 2022-05-29 01:56:40 +03:00 committed by Philip Withnall
parent 7074122f30
commit 7169f6e1e5
2 changed files with 36 additions and 5 deletions

View File

@ -3141,7 +3141,7 @@ g_date_time_format_utf8 (GDateTime *datetime,
g_date_time_get_day_of_month (datetime));
break;
case 'e':
format_number (outstr, alt_digits, pad_set ? pad : " ", 2,
format_number (outstr, alt_digits, pad_set ? pad : "\u2007", 2,
g_date_time_get_day_of_month (datetime));
break;
case 'f':
@ -3355,7 +3355,8 @@ g_date_time_format_utf8 (GDateTime *datetime,
* - \%c: the preferred date and time representation for the current locale
* - \%C: the century number (year/100) as a 2-digit integer (00-99)
* - \%d: the day of the month as a decimal number (range 01 to 31)
* - \%e: the day of the month as a decimal number (range 1 to 31)
* - \%e: the day of the month as a decimal number (range 1 to 31);
* single digits are preceded by a figure space
* - \%F: equivalent to `%Y-%m-%d` (the ISO 8601 date format)
* - \%g: the last two digits of the ISO 8601 week-based year as a
* decimal number (00-99). This works well with \%V and \%u.

View File

@ -1602,7 +1602,8 @@ GDateTime *__dt = g_date_time_new_local (2009, 10, 24, 0, 0, 0);\
TEST_PRINTF ("%B", "October");
TEST_PRINTF ("%d", "24");
TEST_PRINTF_DATE (2009, 1, 1, "%d", "01");
TEST_PRINTF ("%e", "24"); // fixme
TEST_PRINTF ("%e", "24");
TEST_PRINTF_DATE (2009, 1, 1, "%e", "\u20071");
TEST_PRINTF_TIME (10, 10, 1.001, "%f", "001000");
TEST_PRINTF ("%h", "Oct");
TEST_PRINTF ("%H", "00");
@ -1780,7 +1781,7 @@ test_modifiers (void)
TEST_PRINTF_DATE (2009, 1, 21, "%-d", "21");
TEST_PRINTF_DATE (2009, 1, 21, "%0d", "21");
TEST_PRINTF_DATE (2009, 1, 1, "%e", " 1");
TEST_PRINTF_DATE (2009, 1, 1, "%e", "\u20071");
TEST_PRINTF_DATE (2009, 1, 1, "%_e", " 1");
TEST_PRINTF_DATE (2009, 1, 1, "%-e", "1");
TEST_PRINTF_DATE (2009, 1, 1, "%0e", "01");
@ -2462,6 +2463,24 @@ test_format_time_mixed_utf8 (gconstpointer data)
#endif
}
#ifdef __linux__
static gchar *
str_utf8_replace (const gchar *str,
gunichar from,
gunichar to)
{
GString *str_out = g_string_new ("");
for (; *str != '\0'; str = g_utf8_next_char (str))
{
gunichar c = g_utf8_get_char (str);
g_string_append_unichar (str_out, (c == from) ? to : c);
}
return g_string_free (g_steal_pointer (&str_out), FALSE);
}
#endif
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-y2k"
static void
@ -2479,13 +2498,24 @@ test_strftime (void)
GDateTime *date_time;
gchar c_str[1000];
gchar *dt_str;
gchar *dt_str_replaced = NULL, *c_str_replaced = NULL;
date_time = g_date_time_new_from_unix_local (t);
dt_str = g_date_time_format (date_time, TEST_FORMAT);
strftime (c_str, sizeof c_str, TEST_FORMAT, localtime (&t));
g_assert_cmpstr (c_str, ==, dt_str);
/* Ensure the comparison is done insensitively to spaces.
* g_date_time_format() sometimes uses figure spaces (U+2007) whereas
* strftime() currently doesnt, and thats fine. */
dt_str_replaced = str_utf8_replace (dt_str, 0x2007, 0x20);
c_str_replaced = str_utf8_replace (c_str, 0x2007, 0x20);
g_assert_cmpstr (c_str_replaced, ==, dt_str_replaced);
g_date_time_unref (date_time);
g_free (dt_str);
g_free (dt_str_replaced);
g_free (c_str_replaced);
}
#endif
}