[glib/glib-2-62: 1/2] gdatetime: Handle leap seconds in ISO8601 dates
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-62: 1/2] gdatetime: Handle leap seconds in ISO8601 dates
- Date: Mon, 16 Dec 2019 13:33:58 +0000 (UTC)
commit 9ba4060ce211b8f67df28f8009f23089eacc8545
Author: Bastien Nocera <hadess hadess net>
Date: Tue Nov 12 12:59:17 2019 +0100
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 <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:
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
index 4ecccb347..7b95f626b 100644
--- a/glib/tests/gdatetime.c
+++ b/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 },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]