[glib/wip/hadess/gdatetime-leap-seconds] gdatetime: Add hack for leap seconds



commit 57564843bd8de530f7dec1e52a6a597571274641
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Nov 12 12:59:17 2019 +0100

    gdatetime: Add hack for leap seconds
    
    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 1382d3f93..e85a00f56 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;
@@ -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).
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
index 339f6345c..174a1df14 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]