GDateTime doesn't support leap seconds
While trying to port totem-pl-parser away from GTimeVal, I realised that g_time_val_from_iso8601()
could parse this valid ISO8601 string 1990-12-31T15:59:60-08:00
, but that g_date_time_new_from_iso8601()
could not.
g_date_time_new_from_iso8601()
managed to parse the text, but when it comes to calling g_date_time_new()
, it fails.
This hack fixes it, but it probably isn't correct:
diff --git glib/gdatetime.c glib/gdatetime.c
index 1382d3f93..51109dccd 100644
--- glib/gdatetime.c
+++ glib/gdatetime.c
@@ -1194,6 +1194,8 @@ get_iso8601_seconds (const gchar *text, gsize length, gdouble *value)
if (length > 2 && !(text[i] == '.' || text[i] == ','))
return FALSE;
+ if (v >= 60.0 && v <= 61.0)
+ v = 59.0;
i++;
if (i == length)
return FALSE;
diff --git glib/tests/gdatetime.c glib/tests/gdatetime.c
index 339f6345c..174a1df14 100644
--- glib/tests/gdatetime.c
+++ glib/tests/gdatetime.c
@@ -818,6 +818,7 @@ test_GDateTime_new_from_iso8601_2 (void)
{ TRUE, "1970-01-01T00:00:17.1234Z", 1970, 1, 1, 0, 0, 17, 123400, 0 },
{ TRUE, "1970-01-01T00:00:17.123456Z", 1970, 1, 1, 0, 0, 17, 123456, 0 },
{ TRUE, "1980-02-22T12:36:00+02:00", 1980, 2, 22, 12, 36, 0, 0, 2 * G_TIME_SPAN_HOUR },
+ { TRUE, "1990-12-31T15:59:60-08:00", 1990, 12, 31, 15, 59, 59, 0, -8 * G_TIME_SPAN_HOUR },
{ FALSE, " ", 0, 0, 0, 0, 0, 0, 0, 0 },
{ FALSE, "x", 0, 0, 0, 0, 0, 0, 0, 0 },
{ FALSE, "123x", 0, 0, 0, 0, 0, 0, 0, 0 },