gdatetime: Add %f format specifier for microseconds

Same specifier used as in pythons datetime.strptime

Change-Id: Ic15a63e3c83674b2e8a05bc79ef2665738e71a5a
This commit is contained in:
Johan Bjäreholt 2020-08-05 13:27:47 +02:00
parent e4f4a40fb4
commit 3b0eca5be6
2 changed files with 8 additions and 2 deletions

View File

@ -3132,6 +3132,10 @@ g_date_time_format_utf8 (GDateTime *datetime,
format_number (outstr, alt_digits, pad_set ? pad : " ", 2,
g_date_time_get_day_of_month (datetime));
break;
case 'f':
g_string_append_printf (outstr, "%06" G_GUINT64_FORMAT,
datetime->usec % G_TIME_SPAN_SECOND);
break;
case 'F':
g_string_append_printf (outstr, "%d-%02d-%02d",
g_date_time_get_year (datetime),
@ -3323,7 +3327,7 @@ g_date_time_format_utf8 (GDateTime *datetime,
* strftime() format language as specified by C99. The \%D, \%U and \%W
* conversions are not supported, nor is the 'E' modifier. The GNU
* extensions \%k, \%l, \%s and \%P are supported, however, as are the
* '0', '_' and '-' modifiers.
* '0', '_' and '-' modifiers. The Python extension \%f is also supported.
*
* In contrast to strftime(), this function always produces a UTF-8
* string, regardless of the current locale. Note that the rendering of
@ -3355,6 +3359,7 @@ g_date_time_format_utf8 (GDateTime *datetime,
* single digits are preceded by a blank
* - \%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)
* - \%p: either "AM" or "PM" according to the given time value, or the
* corresponding strings for the current locale. Noon is treated as
* "PM" and midnight as "AM". Use of this format specifier is discouraged, as
@ -3399,7 +3404,7 @@ g_date_time_format_utf8 (GDateTime *datetime,
* conversion specifier by one or more modifier characters. The
* following modifiers are supported for many of the numeric
* conversions:
*
*
* - O: Use alternative numeric symbols, if the current locale supports those.
* - _: Pad a numeric result with spaces. This overrides the default padding
* for the specifier.

View File

@ -1530,6 +1530,7 @@ GDateTime *__dt = g_date_time_new_local (2009, 10, 24, 0, 0, 0);\
TEST_PRINTF ("%d", "24");
TEST_PRINTF_DATE (2009, 1, 1, "%d", "01");
TEST_PRINTF ("%e", "24"); // fixme
TEST_PRINTF_TIME (10, 10, 1.001, "%f", "001000");
TEST_PRINTF ("%h", "Oct");
TEST_PRINTF ("%H", "00");
TEST_PRINTF_TIME (15, 0, 0, "%H", "15");