Merge branch 'wip/carlosg/gdatetime-before-y1000' into 'main'

glib: Format GDateTime ISO8601 years as %C%y

See merge request GNOME/glib!2563
This commit is contained in:
Philip Withnall 2022-03-21 13:47:48 +00:00
commit 56a3747038
2 changed files with 18 additions and 2 deletions

View File

@ -3492,12 +3492,12 @@ g_date_time_format_iso8601 (GDateTime *datetime)
GString *outstr = NULL;
gchar *main_date = NULL;
gint64 offset;
gchar *format = "%Y-%m-%dT%H:%M:%S";
gchar *format = "%C%y-%m-%dT%H:%M:%S";
/* if datetime has sub-second non-zero values below the second precision we
* should print them as well */
if (datetime->usec % G_TIME_SPAN_SECOND != 0)
format = "%Y-%m-%dT%H:%M:%S.%f";
format = "%C%y-%m-%dT%H:%M:%S.%f";
/* Main date and time. */
main_date = g_date_time_format (datetime, format);

View File

@ -2321,6 +2321,22 @@ test_format_iso8601 (void)
g_free (p);
g_date_time_unref (dt);
g_time_zone_unref (tz);
tz = g_time_zone_new_utc ();
dt = g_date_time_new (tz, 9, 1, 2, 3, 4, 55);
p = g_date_time_format_iso8601 (dt);
g_assert_cmpstr (p, ==, "0009-01-02T03:04:55Z");
g_free (p);
g_date_time_unref (dt);
g_time_zone_unref (tz);
tz = g_time_zone_new_utc ();
dt = g_date_time_new (tz, 9990, 1, 2, 3, 4, 55.000001);
p = g_date_time_format_iso8601 (dt);
g_assert_cmpstr (p, ==, "9990-01-02T03:04:55.000001Z");
g_free (p);
g_date_time_unref (dt);
g_time_zone_unref (tz);
}
typedef struct