[glib: 2/4] gdatetime: Pad numbers with numeric space
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 2/4] gdatetime: Pad numbers with numeric space
- Date: Mon, 20 Jun 2022 14:04:00 +0000 (UTC)
commit 7074122f308b7b3402fba250f2010778fdad6eff
Author: Maksym Hazevych <dpadar protonmail com>
Date: Sat May 28 16:57:06 2022 +0300
gdatetime: Pad numbers with numeric space
Padding numbers with a typical space character doesn't align them well
because it has a different size. Instead, we need to use the "U+2007"
figure (numeric) space that has the same size as a numerical digit.
This is only visible when using the `tnum` font feature that
makes numbers monospace.
Closes #2655
glib/gdatetime.c | 8 ++++----
glib/tests/gdatetime.c | 10 +++++-----
2 files changed, 9 insertions(+), 9 deletions(-)
---
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
index 7d3d272138..0d2f5334da 100644
--- a/glib/gdatetime.c
+++ b/glib/gdatetime.c
@@ -3189,11 +3189,11 @@ g_date_time_format_utf8 (GDateTime *datetime,
g_date_time_get_day_of_year (datetime));
break;
case 'k':
- format_number (outstr, alt_digits, pad_set ? pad : " ", 2,
+ format_number (outstr, alt_digits, pad_set ? pad : "\u2007", 2,
g_date_time_get_hour (datetime));
break;
case 'l':
- format_number (outstr, alt_digits, pad_set ? pad : " ", 2,
+ format_number (outstr, alt_digits, pad_set ? pad : "\u2007", 2,
(g_date_time_get_hour (datetime) + 11) % 12 + 1);
break;
case 'm':
@@ -3366,9 +3366,9 @@ g_date_time_format_utf8 (GDateTime *datetime,
* - \%I: the hour as a decimal number using a 12-hour clock (range 01 to 12)
* - \%j: the day of the year as a decimal number (range 001 to 366)
* - \%k: the hour (24-hour clock) as a decimal number (range 0 to 23);
- * single digits are preceded by a blank
+ * single digits are preceded by a figure space
* - \%l: the hour (12-hour clock) as a decimal number (range 1 to 12);
- * single digits are preceded by a blank
+ * single digits are preceded by a figure space
* - \%m: the month as a decimal number (range 01 to 12)
* - \%M: the minute as a decimal number (range 00 to 59)
* - \%f: the microsecond as a decimal number (range 000000 to 999999)
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
index dd83ce7ba7..3820d233e1 100644
--- a/glib/tests/gdatetime.c
+++ b/glib/tests/gdatetime.c
@@ -1611,11 +1611,11 @@ GDateTime *__dt = g_date_time_new_local (2009, 10, 24, 0, 0, 0);\
TEST_PRINTF_TIME (12, 0, 0, "%I", "12");
TEST_PRINTF_TIME (15, 0, 0, "%I", "03");
TEST_PRINTF ("%j", "297");
- TEST_PRINTF ("%k", " 0");
+ TEST_PRINTF ("%k", "\u20070");
TEST_PRINTF_TIME (13, 13, 13, "%k", "13");
TEST_PRINTF ("%l", "12");
TEST_PRINTF_TIME (12, 0, 0, "%I", "12");
- TEST_PRINTF_TIME (13, 13, 13, "%l", " 1");
+ TEST_PRINTF_TIME (13, 13, 13, "%l", "\u20071");
TEST_PRINTF_TIME (10, 13, 13, "%l", "10");
TEST_PRINTF ("%m", "10");
TEST_PRINTF ("%M", "00");
@@ -1711,7 +1711,7 @@ test_non_utf8_printf (void)
TEST_PRINTF_TIME (13, 13, 13, "%k", "13");
TEST_PRINTF ("%l", "12");
TEST_PRINTF_TIME (12, 0, 0, "%I", "12");
- TEST_PRINTF_TIME (13, 13, 13, "%l", " 1");
+ TEST_PRINTF_TIME (13, 13, 13, "%l", "\u20071");
TEST_PRINTF_TIME (10, 13, 13, "%l", "10");
TEST_PRINTF ("%m", "10");
TEST_PRINTF ("%M", "00");
@@ -1807,12 +1807,12 @@ test_modifiers (void)
TEST_PRINTF_TIME (23, 0, 0, "%-I", "11");
TEST_PRINTF_TIME (23, 0, 0, "%0I", "11");
- TEST_PRINTF_TIME ( 1, 0, 0, "%k", " 1");
+ TEST_PRINTF_TIME ( 1, 0, 0, "%k", "\u20071");
TEST_PRINTF_TIME ( 1, 0, 0, "%_k", " 1");
TEST_PRINTF_TIME ( 1, 0, 0, "%-k", "1");
TEST_PRINTF_TIME ( 1, 0, 0, "%0k", "01");
- TEST_PRINTF_TIME ( 1, 0, 0, "%l", " 1");
+ TEST_PRINTF_TIME ( 1, 0, 0, "%l", "\u20071");
TEST_PRINTF_TIME ( 1, 0, 0, "%_l", " 1");
TEST_PRINTF_TIME ( 1, 0, 0, "%-l", "1");
TEST_PRINTF_TIME ( 1, 0, 0, "%0l", "01");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]