mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-09 02:46:16 +01:00
gdatetime: Handle leap seconds in ISO8601 dates
GDateTime doesn't handle leap seconds, so just round these down to the previous second. https://gitlab.gnome.org/GNOME/glib/issues/1938
This commit is contained in:
parent
d8b45684ed
commit
b4eaac5817
@ -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;
|
||||
@ -1433,6 +1438,10 @@ parse_iso8601_time (const gchar *text, gsize length,
|
||||
* some extensions from [RFC 3339](https://tools.ietf.org/html/rfc3339) as
|
||||
* mentioned below.
|
||||
*
|
||||
* 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 ' '. The latter two
|
||||
* separators are an extension from
|
||||
* [RFC 3339](https://tools.ietf.org/html/rfc3339#section-5.6).
|
||||
|
@ -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 },
|
||||
|
Loading…
Reference in New Issue
Block a user