Merge branch 'backport-1233-iso8601-leap-seconds-glib-2-62' into 'glib-2-62'

Backport !1233 “gdatetime: Handle leap seconds in ISO8601 dates” to glib-2-62

See merge request GNOME/glib!1240
This commit is contained in:
Emmanuele Bassi 2019-12-16 13:33:31 +00:00
commit f1acda4dda
2 changed files with 10 additions and 0 deletions

View File

@ -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 <date><sep><time><tz> are supported.
*
* Note that as #GDateTime "is oblivious to leap seconds", leap seconds information
* in an ISO-8601 string will be ignored, so a `23:59:60` time would be parsed as
* `23:59:59`.
*
* <sep> is the separator and can be either 'T', 't' or ' '.
*
* <date> is in the form:

View File

@ -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 },