From 9ba4060ce211b8f67df28f8009f23089eacc8545 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Tue, 12 Nov 2019 12:59:17 +0100 Subject: [PATCH] gdatetime: Handle leap seconds in ISO8601 dates GDateTime doesn't handle leap seconds, so just round these down to the previous second. (Cherry-pick had minor conflicts in the documentation.) https://gitlab.gnome.org/GNOME/glib/issues/1938 --- glib/gdatetime.c | 9 +++++++++ glib/tests/gdatetime.c | 1 + 2 files changed, 10 insertions(+) diff --git a/glib/gdatetime.c b/glib/gdatetime.c index 3be4eba3d..f8bf31c43 100644 --- a/glib/gdatetime.c +++ b/glib/gdatetime.c @@ -1194,6 +1194,11 @@ get_iso8601_seconds (const gchar *text, gsize length, gdouble *value) if (length > 2 && !(text[i] == '.' || text[i] == ',')) return FALSE; + + /* Ignore leap seconds, see g_date_time_new_from_iso8601() */ + if (v >= 60.0 && v <= 61.0) + v = 59.0; + i++; if (i == length) return FALSE; @@ -1431,6 +1436,10 @@ parse_iso8601_time (const gchar *text, gsize length, * [ISO 8601 formatted string](https://en.wikipedia.org/wiki/ISO_8601) * @text. ISO 8601 strings of the form