[libgdata] core: Re-add ISO 8601 formatting workaround for dates



commit bfbd4f5ca493f17fe2300e54092a4ec27f65ea08
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Mar 5 16:12:08 2017 +0000

    core: Re-add ISO 8601 formatting workaround for dates
    
    This reverts commit 732017e4e5235e28c578cc3367fa0c4548b65495.
    
    The problem has re-appeared with the Google Tasks API: timestamps once
    more have to be defined with microseconds included.
    
    See https://bugzilla.gnome.org/show_bug.cgi?id=737799.

 gdata/gdata-parser.c   |   20 +++++++++++++++++++-
 gdata/tests/calendar.c |   14 +++++++-------
 gdata/tests/general.c  |   34 +++++++++++++++++-----------------
 gdata/tests/tasks.c    |   38 +++++++++++++++++++-------------------
 4 files changed, 62 insertions(+), 44 deletions(-)
---
diff --git a/gdata/gdata-parser.c b/gdata/gdata-parser.c
index a43c2ec..74871c7 100644
--- a/gdata/gdata-parser.c
+++ b/gdata/gdata-parser.c
@@ -241,11 +241,29 @@ gchar *
 gdata_parser_int64_to_iso8601 (gint64 _time)
 {
        GTimeVal time_val;
+       gchar *iso8601;
+       gchar **date_time_components;
+       gchar *retval;
 
        time_val.tv_sec = _time;
        time_val.tv_usec = 0;
 
-       return g_time_val_to_iso8601 (&time_val);
+       iso8601 = g_time_val_to_iso8601 (&time_val);
+
+       /* FIXME: Work around for Google's incorrect ISO 8601 implementation.
+        * They appear to not like dates in the format ‘2014-08-09T21:07:05Z’
+        * which specify a timezone using ‘Z’ and no microseconds.
+        *
+        * See: https://bugzilla.gnome.org/show_bug.cgi?id=732809
+        * https://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3595
+        * http://stackoverflow.com/a/17630320/2931197 */
+       date_time_components = g_strsplit (iso8601, "Z", 2);
+       retval = g_strjoinv (".000001+00:00", date_time_components);
+       g_strfreev (date_time_components);
+
+       g_free (iso8601);
+
+       return retval;
 }
 
 gboolean
diff --git a/gdata/tests/calendar.c b/gdata/tests/calendar.c
index 4d70d1b..442374d 100644
--- a/gdata/tests/calendar.c
+++ b/gdata/tests/calendar.c
@@ -619,11 +619,11 @@ test_event_json (void)
                "'guestsCanSeeOtherGuests': false,"
                "'anyoneCanAddSelf': false,"
                "'start': {"
-                       "'dateTime': '2009-04-17T15:00:00Z',"
+                       "'dateTime': '2009-04-17T15:00:00.000001+00:00',"
                        "'timeZone': 'UTC'"
                "},"
                "'end': {"
-                       "'dateTime': '2009-04-17T17:00:00Z',"
+                       "'dateTime': '2009-04-17T17:00:00.000001+00:00',"
                        "'timeZone': 'UTC'"
                "},"
                "'attendees': ["
@@ -758,11 +758,11 @@ test_event_json_dates (void)
                "}", TRUE, 1239926400, 1239926400 + 86400, NULL },
                /* Full date and time. */
                { "'start': {"
-                       "'dateTime': '2009-04-17T15:00:00Z',"
+                       "'dateTime': '2009-04-17T15:00:00.000001+00:00',"
                        "'timeZone': 'UTC'"
                "},"
                "'end': {"
-                       "'dateTime': '2009-04-17T16:00:00Z',"
+                       "'dateTime': '2009-04-17T16:00:00.000001+00:00',"
                        "'timeZone': 'UTC'"
                "}", FALSE, 1239926400 + 54000, 1239926400 + 54000 + 3600, NULL },
                /* Start and end time. */
@@ -1152,21 +1152,21 @@ G_GNUC_END_IGNORE_DEPRECATIONS
        /* Check the built query URI with a normal feed URI */
        query_uri = gdata_query_get_query_uri (GDATA_QUERY (query), "http://example.com";);
        g_assert_cmpstr (query_uri, ==, "http://example.com?q=q&orderBy=startTime&singleEvents=true";
-                                       
"&timeMin=2009-04-17T15:00:00Z&timeMax=2010-04-17T15:00:00Z&timeZone=America%2FLos_Angeles&maxAttendees=15"
+                                       
"&timeMin=2009-04-17T15:00:00.000001+00:00&timeMax=2010-04-17T15:00:00.000001+00:00&timeZone=America%2FLos_Angeles&maxAttendees=15"
                                        "&showDeleted=true");
        g_free (query_uri);
 
        /* …with a feed URI with a trailing slash */
        query_uri = gdata_query_get_query_uri (GDATA_QUERY (query), "http://example.com/";);
        g_assert_cmpstr (query_uri, ==, "http://example.com/?q=q&orderBy=startTime&singleEvents=true";
-                                       
"&timeMin=2009-04-17T15:00:00Z&timeMax=2010-04-17T15:00:00Z&timeZone=America%2FLos_Angeles&maxAttendees=15"
+                                       
"&timeMin=2009-04-17T15:00:00.000001+00:00&timeMax=2010-04-17T15:00:00.000001+00:00&timeZone=America%2FLos_Angeles&maxAttendees=15"
                                        "&showDeleted=true");
        g_free (query_uri);
 
        /* …with a feed URI with pre-existing arguments */
        query_uri = gdata_query_get_query_uri (GDATA_QUERY (query), 
"http://example.com/bar/?test=test&this=that";);
        g_assert_cmpstr (query_uri, ==, "http://example.com/bar/?test=test&this=that&q=q&orderBy=startTime";
-                                       
"&singleEvents=true&timeMin=2009-04-17T15:00:00Z&timeMax=2010-04-17T15:00:00Z"
+                                       
"&singleEvents=true&timeMin=2009-04-17T15:00:00.000001+00:00&timeMax=2010-04-17T15:00:00.000001+00:00"
                                        "&timeZone=America%2FLos_Angeles&maxAttendees=15&showDeleted=true");
        g_free (query_uri);
 
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index f1ab7cb..6b41f25 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -528,8 +528,8 @@ test_entry_parse_xml (void)
                         "<?xml version='1.0' encoding='UTF-8'?>"
                         "<entry xmlns='http://www.w3.org/2005/Atom' 
xmlns:gd='http://schemas.google.com/g/2005' xmlns:ns='http://example.com/'>"
                                "<title type='text'>Testing unhandled XML</title>"
-                               "<updated>2009-01-25T14:07:37Z</updated>"
-                               "<published>2009-01-23T14:06:37Z</published>"
+                               "<updated>2009-01-25T14:07:37.000001+00:00</updated>"
+                               "<published>2009-01-23T14:06:37.000001+00:00</published>"
                                "<content type='text'>Here we test unhandled XML elements.</content>"
                                "<foobar>Test!</foobar>"
                                "<barfoo shizzle=\"zing\"/>"
@@ -569,8 +569,8 @@ test_entry_parse_xml_kind_category (void)
                         "<?xml version='1.0' encoding='UTF-8'?>"
                         "<entry xmlns='http://www.w3.org/2005/Atom' 
xmlns:gd='http://schemas.google.com/g/2005'>"
                                "<title type='text'>Testing kind categories</title>"
-                               "<updated>2009-01-25T14:07:37Z</updated>"
-                               "<published>2009-01-23T14:06:37Z</published>"
+                               "<updated>2009-01-25T14:07:37.000001+00:00</updated>"
+                               "<published>2009-01-23T14:06:37.000001+00:00</published>"
                                "<content type='text'>Here we test kind categories.</content>"
                        "<category term='http://schemas.google.com/docs/2007#file' "
                                  "scheme='http://schemas.google.com/g/2005#kind' "
@@ -620,7 +620,7 @@ test_entry_parse_json (void)
                "{"
                        "\"title\":\"A title\","
                        "\"id\":\"some-id\","
-                       "\"updated\":\"2009-01-25T14:07:37Z\","
+                       "\"updated\":\"2009-01-25T14:07:37.000001+00:00\","
                        "\"etag\":\"some-etag\","
                        "\"selfLink\":\"http://example.com/\",";
                        "\"kind\":\"kind#kind\","
@@ -760,8 +760,8 @@ test_entry_escaping (void)
                "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>"
                        "<title type='text'>Escaped content &amp; stuff</title>"
                        "<id>http://foo.com/?foo&amp;bar</id>"
-                       "<updated>2010-12-10T17:21:24Z</updated>"
-                       "<published>2010-12-10T17:21:24Z</published>"
+                       "<updated>2010-12-10T17:21:24.000001+00:00</updated>"
+                       "<published>2010-12-10T17:21:24.000001+00:00</published>"
                        "<summary type='text'>Summary &amp; stuff</summary>"
                        "<rights>Free &amp; open source</rights>"
                        "<content type='text'>Content &amp; things.</content>"
@@ -1106,7 +1106,7 @@ test_feed_escaping (void)
                "<feed xmlns='http://www.w3.org/2005/Atom'>"
                        "<title type='text'>Test feed &amp; stuff.</title>"
                        "<id>http://foo.com?foo&amp;bar</id>"
-                       "<updated>2010-12-10T17:49:15Z</updated>"
+                       "<updated>2010-12-10T17:49:15.000001+00:00</updated>"
                "</feed>");
        g_object_unref (feed);
 }
@@ -1157,28 +1157,28 @@ test_query_dates (void)
        /* updated-min */
        gdata_query_set_updated_min (query, 1373280114); /* 2013-07-08T10:41:54Z */
        query_uri = gdata_query_get_query_uri (query, "http://example.com";);
-       g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&updated-min=2013-07-08T10:41:54Z";);
+       g_assert_cmpstr (query_uri, ==, 
"http://example.com?q=baz&updated-min=2013-07-08T10:41:54.000001+00:00";);
        g_free (query_uri);
        gdata_query_set_updated_min (query, -1);
 
        /* updated-max */
        gdata_query_set_updated_max (query, 1373280114); /* 2013-07-08T10:41:54Z */
        query_uri = gdata_query_get_query_uri (query, "http://example.com";);
-       g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&updated-max=2013-07-08T10:41:54Z";);
+       g_assert_cmpstr (query_uri, ==, 
"http://example.com?q=baz&updated-max=2013-07-08T10:41:54.000001+00:00";);
        g_free (query_uri);
        gdata_query_set_updated_max (query, -1);
 
        /* published-min */
        gdata_query_set_published_min (query, 1373280114); /* 2013-07-08T10:41:54Z */
        query_uri = gdata_query_get_query_uri (query, "http://example.com";);
-       g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&published-min=2013-07-08T10:41:54Z";);
+       g_assert_cmpstr (query_uri, ==, 
"http://example.com?q=baz&published-min=2013-07-08T10:41:54.000001+00:00";);
        g_free (query_uri);
        gdata_query_set_published_min (query, -1);
 
        /* published-max */
        gdata_query_set_published_max (query, 1373280114); /* 2013-07-08T10:41:54Z */
        query_uri = gdata_query_get_query_uri (query, "http://example.com";);
-       g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&published-max=2013-07-08T10:41:54Z";);
+       g_assert_cmpstr (query_uri, ==, 
"http://example.com?q=baz&published-max=2013-07-08T10:41:54.000001+00:00";);
        g_free (query_uri);
        gdata_query_set_published_max (query, -1);
 
@@ -3254,7 +3254,7 @@ test_gd_reminder (void)
        gdata_test_assert_xml (reminder,
                         "<?xml version='1.0' encoding='UTF-8'?>"
                         "<gd:reminder xmlns='http://www.w3.org/2005/Atom' 
xmlns:gd='http://schemas.google.com/g/2005' "
-                               "absoluteTime='2005-06-07T00:55:00Z' method='alert'/>");
+                               "absoluteTime='2005-06-07T00:55:00.000001+00:00' method='alert'/>");
        g_object_unref (reminder);
 }
 
@@ -3349,8 +3349,8 @@ test_gd_when (void)
        /* Check the outputted XML is the same */
        gdata_test_assert_xml (when,
                         "<?xml version='1.0' encoding='UTF-8'?>"
-                        "<gd:when xmlns='http://www.w3.org/2005/Atom' 
xmlns:gd='http://schemas.google.com/g/2005' startTime='2005-06-07T01:00:00Z' "
-                               "endTime='2005-06-07T02:00:00Z'/>");
+                        "<gd:when xmlns='http://www.w3.org/2005/Atom' 
xmlns:gd='http://schemas.google.com/g/2005' startTime='2005-06-07T01:00:00.000001+00:00' "
+                               "endTime='2005-06-07T02:00:00.000001+00:00'/>");
        g_object_unref (when);
 
        /* Now parse a time with different information */
@@ -3392,7 +3392,7 @@ test_gd_when (void)
                         "<gd:when xmlns='http://www.w3.org/2005/Atom' 
xmlns:gd='http://schemas.google.com/g/2005' startTime='2005-06-06' "
                                "endTime='2005-06-08' valueString='This weekend'>"
                                "<gd:reminder minutes='15'/>"
-                               "<gd:reminder absoluteTime='2005-06-06T00:00:00Z' method='alert'/>"
+                               "<gd:reminder absoluteTime='2005-06-06T00:00:00.000001+00:00' 
method='alert'/>"
                                "<foobar/>"
                         "</gd:when>");
        g_object_unref (when);
@@ -3412,7 +3412,7 @@ test_gd_when_escaping (void)
        gdata_test_assert_xml (when,
                         "<?xml version='1.0' encoding='UTF-8'?>"
                         "<gd:when xmlns='http://www.w3.org/2005/Atom' 
xmlns:gd='http://schemas.google.com/g/2005' "
-                                 "startTime='2005-06-07T01:00:00Z' valueString='Value string &amp; 
stuff!'/>");
+                                 "startTime='2005-06-07T01:00:00.000001+00:00' valueString='Value string 
&amp; stuff!'/>");
        g_object_unref (when);
 }
 
diff --git a/gdata/tests/tasks.c b/gdata/tests/tasks.c
index 2e9a03e..d8583b5 100644
--- a/gdata/tests/tasks.c
+++ b/gdata/tests/tasks.c
@@ -122,14 +122,14 @@ test_query_uri (void)
        g_assert_cmpstr (query_uri, ==,
                         "http://example.com";
                         /* FIXME: First two are outdated fallbacks */
-                        "?updated-min=1970-01-01T01:53:09Z"
+                        "?updated-min=1970-01-01T01:53:09.000001+00:00"
                         "&max-results=10"
                         "&maxResults=10"
-                        "&updatedMin=1970-01-01T01:53:09Z"
-                        "&completedMin=1970-01-01T01:34:38Z"
-                        "&completedMax=1970-01-01T00:20:34Z"
-                        "&dueMin=1970-01-01T00:39:05Z"
-                        "&dueMax=1970-01-01T00:57:36Z"
+                        "&updatedMin=1970-01-01T01:53:09.000001+00:00"
+                        "&completedMin=1970-01-01T01:34:38.000001+00:00"
+                        "&completedMax=1970-01-01T00:20:34.000001+00:00"
+                        "&dueMin=1970-01-01T00:39:05.000001+00:00"
+                        "&dueMax=1970-01-01T00:57:36.000001+00:00"
                         "&showCompleted=true"
                         "&showDeleted=true"
                         "&showHidden=true");
@@ -150,14 +150,14 @@ test_query_uri (void)
                                               "http://example.com";);
        g_assert_cmpstr (query_uri, ==,
                         "http://example.com";
-                        "?updated-min=1970-01-01T01:53:09Z"
+                        "?updated-min=1970-01-01T01:53:09.000001+00:00"
                         "&max-results=10"
                         "&maxResults=10"
-                        "&updatedMin=1970-01-01T01:53:09Z"
-                        "&completedMin=1970-01-01T01:34:38Z"
-                        "&completedMax=1970-01-01T00:20:34Z"
-                        "&dueMin=1970-01-01T00:39:05Z"
-                        "&dueMax=1970-01-01T00:57:36Z"
+                        "&updatedMin=1970-01-01T01:53:09.000001+00:00"
+                        "&completedMin=1970-01-01T01:34:38.000001+00:00"
+                        "&completedMax=1970-01-01T00:20:34.000001+00:00"
+                        "&dueMin=1970-01-01T00:39:05.000001+00:00"
+                        "&dueMax=1970-01-01T00:57:36.000001+00:00"
                         "&showCompleted=false"
                         "&showDeleted=false"
                         "&showHidden=false");
@@ -322,8 +322,8 @@ test_task_properties (void)
                        "\"title\": \"some-other-title\","
                        "\"notes\": \"more-notes\","
                        "\"status\": \"completed\","
-                       "\"due\": \"2014-08-30T17:20:00Z\","
-                       "\"completed\": \"2014-08-30T17:20:00Z\","
+                       "\"due\": \"2014-08-30T17:20:00.000001+00:00\","
+                       "\"completed\": \"2014-08-30T17:20:00.000001+00:00\","
                        "\"deleted\": true,"
                        "\"hidden\": false"
                "}");
@@ -337,8 +337,8 @@ test_task_properties (void)
                        "\"title\": \"some-other-title\","
                        "\"notes\": \"more-notes\","
                        "\"status\": \"completed\","
-                       "\"due\": \"2014-08-30T17:20:00Z\","
-                       "\"completed\": \"2014-08-30T17:20:00Z\","
+                       "\"due\": \"2014-08-30T17:20:00.000001+00:00\","
+                       "\"completed\": \"2014-08-30T17:20:00.000001+00:00\","
                        "\"deleted\": false,"
                        "\"hidden\": false"
                "}");
@@ -501,14 +501,14 @@ test_task_parser_normal (void)
                        "\"id\": \"some-id\","
                        "\"etag\": \"some-etag\","
                        "\"title\": \"some-title \\\"with quotes\\\"\","
-                       "\"updated\": \"2014-08-30T19:40:00Z\","
+                       "\"updated\": \"2014-08-30T19:40:00.000001+00:00\","
                        "\"selfLink\": \"http://some-uri/\",";
                        "\"parent\": \"some-parent-id\","
                        "\"position\": \"some-position\","
                        "\"notes\": \"Some notes!\","
                        "\"status\": \"needsAction\","
-                       "\"due\": \"2014-08-30T20:00:00Z\","
-                       "\"completed\": \"2014-08-30T20:10:05Z\","
+                       "\"due\": \"2014-08-30T20:00:00.000001+00:00\","
+                       "\"completed\": \"2014-08-30T20:10:05.000001+00:00\","
                        "\"deleted\": false,"
                        "\"hidden\": true,"
                        /* Unhandled for the moment: */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]