[libgda] GdaTime: reimplemented as a GDateTime



commit e6d48ef55c9c94781b348572718a46afedc36863
Author: Daniel Espinosa <esodan gmail com>
Date:   Sun Apr 21 21:58:12 2019 -0500

    GdaTime: reimplemented as a GDateTime
    
    GdaTime is now a GDateTime boxed, requiring API changes.
    
    Fixes memory leaks.

 libgda/gda-statement.c                      |  29 ++--
 libgda/gda-util.c                           |  82 +++++------
 libgda/gda-util.h                           |   4 +-
 libgda/gda-value.c                          | 216 +++++-----------------------
 libgda/gda-value.h                          |  10 +-
 libgda/handlers/gda-handler-time.c          | 100 +++----------
 libgda/sqlite/gda-sqlite-provider.c         |  24 +---
 libgda/sqlite/gda-sqlite-recordset.c        |  18 ++-
 libgda/sqlite/virtual/gda-vconnection-hub.c |   4 +-
 providers/mysql/gda-mysql-provider.c        |  20 +--
 providers/postgres/gda-postgres-provider.c  |  24 ++--
 providers/postgres/gda-postgres-recordset.c |   9 +-
 tests/data-models/check_vcnc.c              | 102 +++++++------
 tests/test-input-parsers.c                  |  13 +-
 14 files changed, 211 insertions(+), 444 deletions(-)
---
diff --git a/libgda/gda-statement.c b/libgda/gda-statement.c
index 40e8868c1..960f0b049 100644
--- a/libgda/gda-statement.c
+++ b/libgda/gda-statement.c
@@ -753,21 +753,20 @@ default_render_value (const GValue *value, GdaSqlRenderingContext *context, GErr
                }
                if (context->flags & GDA_STATEMENT_SQL_TIMEZONE_TO_GMT) {
                        if (g_type_is_a (G_VALUE_TYPE (value), GDA_TYPE_TIME)) {
-                               GdaTime *nts;
-                               nts = (GdaTime*) gda_value_get_time (value);
-                               if (nts && (gda_time_get_timezone (nts) != GDA_TIMEZONE_INVALID)) {
-                                       nts = gda_time_copy (nts);
-                                       gda_time_change_timezone (nts, 0);
-                                       gda_time_set_timezone (nts, GDA_TIMEZONE_INVALID);
-                                       GValue v = {0};
-                                       g_value_init (&v, GDA_TYPE_TIME);
-                                       gda_value_set_time (&v, nts);
-                                       gda_time_free (nts);
-                                       gchar *tmp;
-                                       tmp = gda_data_handler_get_sql_from_value (dh, &v);
-                                       g_value_reset (&v);
-                                       return tmp;
-                               }
+                               GdaTime *t;
+        GdaTime *nt;
+                               t = g_value_get_boxed (value);
+
+        if (t != NULL) {
+          nt = gda_time_to_utc (t);
+                           GValue v = {0};
+                           g_value_init (&v, GDA_TYPE_TIME);
+                           g_value_take_boxed (&v, nt);
+                                 gchar *tmp;
+                                 tmp = gda_data_handler_get_sql_from_value (dh, &v);
+                                 g_value_reset (&v);
+                                 return tmp;
+        }
                        }
                        else if (g_type_is_a (G_VALUE_TYPE (value), G_TYPE_DATE_TIME)) {
                                GDateTime *nts;
diff --git a/libgda/gda-util.c b/libgda/gda-util.c
index 436bb52b1..66ea1b2dd 100644
--- a/libgda/gda-util.c
+++ b/libgda/gda-util.c
@@ -3192,8 +3192,8 @@ gda_parse_formatted_date (GDate *gdate, const gchar *value, GDateDMY first, GDat
 }
 
 
-static gboolean
-_parse_iso8601_time (GdaTime *timegda, const gchar *value, gchar sep, glong timezone, const char 
**out_endptr)
+static GdaTime *
+_parse_iso8601_time (const gchar *value, gchar sep, glong timezone, const char **out_endptr)
 {
        unsigned long int tmp;
        const char *endptr;
@@ -3204,18 +3204,18 @@ _parse_iso8601_time (GdaTime *timegda, const gchar *value, gchar sep, glong time
 
 
        if ((*value < '0') || (*value > '9'))
-               return FALSE;
+               return NULL;
 
        /* hour */
        guint8 iter;
        for (iter = 0, tmp = 0, endptr = value; (*endptr >= '0') && (*endptr <= '9') && (iter < 2); iter++, 
endptr++) {
                tmp = tmp * 10 + *endptr - '0';
                if (tmp > 23)
-                       return FALSE;
+                       return NULL;
        }
        h = tmp;
        if ((sep && *endptr != sep) || !*endptr)
-               return FALSE;
+               return NULL;
 
        /* minutes */
        if (sep)
@@ -3223,85 +3223,83 @@ _parse_iso8601_time (GdaTime *timegda, const gchar *value, gchar sep, glong time
        for (tmp = 0, iter = 0 ; (*endptr >= '0') && (*endptr <= '9') && (iter < 2); iter ++, endptr++) {
                tmp = tmp * 10 + *endptr - '0';
                if (tmp > 59)
-                       return FALSE;
+                       return NULL;
        }
        m = tmp;
        if ((sep && *endptr != sep) || !*endptr)
-               return FALSE;
+               return NULL;
 
        /* seconds */
        if (sep)
                endptr++;
        if (sep == 0 && (*endptr == ' ' || *endptr == ':'))
-               return FALSE;
+               return NULL;
        seconds = g_strtod ((const gchar*) endptr, &stz);
        if (seconds >= 60.0) {
                *out_endptr = stz;
-               return FALSE;
+               return NULL;
        }
-       tz = g_time_zone_new_local ();
+       tz = g_time_zone_new_utc ();
        if (stz != NULL) {
                g_time_zone_unref (tz);
                tz = g_time_zone_new (stz);
                if (tz == NULL) {
-                       tz = g_time_zone_new_local ();
+                       tz = g_time_zone_new_utc ();
                }
                for (; *endptr; endptr++);
        }
-       GDateTime *dt = g_date_time_new (tz, 1978, 1, 1, h, m, seconds);
-
-       gda_time_set_from_date_time (timegda, dt);
+       GdaTime *dt = (GdaTime*) g_date_time_new (tz, 1978, 1, 1, h, m, seconds);
 
        g_time_zone_unref (tz);
 
        *out_endptr = endptr;
-       return TRUE;
+       return dt;
 }
 
 /**
  * gda_parse_iso8601_time:
- * @timegda: a pointer to a #GdaTime structure which will be filled
  * @value: a string
  *
  * Extracts time parts from @value, and sets @timegda's contents
  *
- * Accepted date format is "HH:MM:SS[.ms][TZ]" where TZ is +hour or -hour
+ * Accepted date format is "HH:MM:SS[.ms][TZ]" where TZ is +hour or -hour.
+ * If no time zone is given UTC is used.
  *
- * Returns: %TRUE if no error occurred
+ * Returns: (transfer full): a new parsed #GdaTime
  */
-gboolean
-gda_parse_iso8601_time (GdaTime *timegda, const gchar *value)
+GdaTime *
+gda_parse_iso8601_time (const gchar *value)
 {
-       g_return_val_if_fail (timegda, FALSE);
-
        g_return_val_if_fail (value != NULL, FALSE);
-
-       const char *endptr;
-       return _parse_iso8601_time (timegda, value, ':', 0, &endptr);
+  gchar *str = g_strdup_printf ("1970-01-01T%s", value);
+  g_message ("Time ISO to parse: %s", str);
+  GDateTime *dt;
+  GTimeZone *tz = g_time_zone_new_utc ();
+  dt = g_date_time_new_from_iso8601 (str, tz);
+  g_time_zone_unref (tz);
+  g_free (str);
+  str = g_date_time_format (dt, "%FT%T%:z");
+  g_message ("Parsed time: %s", str);
+  g_free (str);
+  return (GdaTime*) dt;
 }
 
 /**
  * gda_parse_formatted_time:
- * @timegda: a pointer to a #GdaTime structure which will be filled
  * @value: a string
  * @sep: the time separator, usually ':'. If equal to @0, then the expexted format will be HHMMSS...
  *
- * Returns: %TRUE if no error occurred
+ * Returns: (transfer full): a new parsed #GdaTime
  *
- * Since: 5.2
+ * Since: 6.0
  */
-gboolean
-gda_parse_formatted_time (GdaTime *timegda, const gchar *value, gchar sep)
+GdaTime *
+gda_parse_formatted_time (const gchar *value, gchar sep)
 {
-       g_return_val_if_fail (timegda, FALSE);
-
        if (!value)
-               return FALSE;
+               return NULL;
        const char *endptr;
-       if (! _parse_iso8601_time (timegda, value, sep, 0, &endptr) || *endptr)
-               return FALSE;
-       else
-               return TRUE;
+       return _parse_iso8601_time (value, sep, 0, &endptr);
 }
 
 /**
@@ -3346,7 +3344,7 @@ gda_parse_formatted_timestamp (const gchar *value,
 
        const char *endptr;
        GDate gdate;
-       GdaTime* timegda = gda_time_new ();
+       GdaTime* timegda = NULL;
 
        if (!value)
                return NULL;
@@ -3363,7 +3361,8 @@ gda_parse_formatted_timestamp (const gchar *value,
                value = endptr + 1;
                if (value != NULL) {
                        /* time part */
-                       if (! _parse_iso8601_time (timegda, value, ':', 0, &endptr) || *endptr)
+      timegda = _parse_iso8601_time (value, ':', 0, &endptr);
+                       if (timegda == NULL  || *endptr)
                                return NULL;
                }
        }
@@ -3383,12 +3382,13 @@ gda_parse_formatted_timestamp (const gchar *value,
                return NULL;
        gdouble seconds;
        seconds = (gdouble) gda_time_get_second (timegda) + gda_time_get_fraction (timegda) / 1000000;
-       return g_date_time_new (tz,
+       GDateTime *ret = g_date_time_new (tz,
                                                                                                        
g_date_get_year (&gdate),
                                                                                                        
g_date_get_month (&gdate),
                                                                                                        
g_date_get_day (&gdate),
                                                                                                        
gda_time_get_hour (timegda),
                                                                                                        
gda_time_get_minute (timegda),
                                                                                                        
seconds);
-
+  gda_time_free (timegda);
+  return ret;
 }
diff --git a/libgda/gda-util.h b/libgda/gda-util.h
index 41560c800..1000fce55 100644
--- a/libgda/gda-util.h
+++ b/libgda/gda-util.h
@@ -118,12 +118,12 @@ void         gda_connection_string_split (const gchar *string, gchar **out_cnc_p
  * Date and time parsing from ISO 8601 (well, part of it)
  */
 gboolean     gda_parse_iso8601_date (GDate *gdate, const gchar *value);
-gboolean     gda_parse_iso8601_time (GdaTime *timegda, const gchar *value);
+GdaTime     *gda_parse_iso8601_time (const gchar *value);
 
 GDateTime    *gda_parse_iso8601_timestamp (const gchar *value);
 gboolean     gda_parse_formatted_date (GDate *gdate, const gchar *value,
                                       GDateDMY first, GDateDMY second, GDateDMY third, gchar sep);
-gboolean     gda_parse_formatted_time (GdaTime *timegda, const gchar *value, gchar sep);
+GdaTime     *gda_parse_formatted_time (const gchar *value, gchar sep);
 GDateTime   *gda_parse_formatted_timestamp (const gchar *value,
                                            GDateDMY first, GDateDMY second, GDateDMY third, gchar sep);
 
diff --git a/libgda/gda-value.c b/libgda/gda-value.c
index e43aa1b6d..b33be0cc8 100644
--- a/libgda/gda-value.c
+++ b/libgda/gda-value.c
@@ -210,12 +210,11 @@ set_from_string (GValue *value, const gchar *as_string)
                        g_date_free (gdate);
        }
        else if (type == GDA_TYPE_TIME) {
-               GdaTime* timegda = gda_time_new ();
-               if (gda_parse_iso8601_time (timegda, as_string)) {
-                       gda_value_set_time (value, timegda);
+               GdaTime* timegda = gda_parse_iso8601_time (as_string);
+    if (timegda != NULL) {
+                       g_value_take_boxed (value, timegda);
                        retval = TRUE;
                }
-               gda_time_free (timegda);
        }
        else if (g_type_is_a (type, G_TYPE_DATE_TIME)) {
     GTimeZone *tz = g_time_zone_new_utc ();
@@ -1459,24 +1458,12 @@ static void
 string_to_time (const GValue *src, GValue *dest)
 {
        const gchar *str = g_value_get_string (src);
-       GdaTime *time = gda_time_new ();
-       gda_parse_iso8601_time (time, str);
-       g_value_set_boxed (dest, time);
-       gda_time_free (time);
+       GdaTime *time = gda_parse_iso8601_time (str);
+  if (time != NULL) {
+         g_value_take_boxed (dest, time);
+  }
 }
 
-/**
- * _GdaTime:
- * @hour: hour representation of the time, as a number between 0 and 23
- * @minute: minute representation of the time, as a number between 0 and 59
- * @second: second representation of the time, as a number between 0 and 59
- * @fraction: fractionnal part of the seconds, in millionth' of second
- * @timezone: number of seconds added to the GMT timezone
- */
-struct _GdaTime {
-       GDateTime *dt;
-};
-
 /**
  * gda_time_copy:
  *
@@ -1485,9 +1472,8 @@ struct _GdaTime {
 GdaTime*
 gda_time_copy (const GdaTime* time)
 {
-
-       GdaTime *c = g_new0(GdaTime, 1);
-       c->dt = g_date_time_add_days (time->dt, 0);
+  GdaTime* c;
+       c = (GdaTime*) g_date_time_add_days ((GDateTime*) time, 0);
        return c;
 }
 
@@ -1500,9 +1486,7 @@ gda_time_copy (const GdaTime* time)
 void
 gda_time_free (GdaTime* boxed)
 {
-       g_date_time_unref (boxed->dt);
-  boxed->dt = NULL;
-       g_free (boxed);
+       g_date_time_unref ((GDateTime*) boxed);
 }
 
 static void
@@ -1544,8 +1528,8 @@ gda_value_take_time (GValue *value, GdaTime *time)
 GdaTime*
 gda_time_new (void)
 {
-       GdaTime *t = g_new0 (GdaTime, 1);
-       t->dt = g_date_time_new_now_local ();
+       GdaTime *t;
+       t = (GdaTime*) g_date_time_new_now_local ();
        return t;
 }
 
@@ -1563,11 +1547,7 @@ gchar*
 gda_time_to_string (GdaTime *time)
 {
        gchar *str;
-       GTimeZone *tz = g_time_zone_new_local ();
-       GDateTime *ndt = g_date_time_to_timezone (time->dt, tz);
-       str = g_date_time_format (ndt, "%H:%M:%S%:::z");
-       g_time_zone_unref (tz);
-       g_date_time_unref (ndt);
+       str = g_date_time_format ((GDateTime*) time, "%H:%M:%S%:::z");
        return str;
 }
 
@@ -1584,10 +1564,8 @@ gchar*
 gda_time_to_string_local (GdaTime *time)
 {
        gchar *str;
-       GTimeZone *tz = g_time_zone_new_local ();
-       GDateTime *ndt = g_date_time_to_timezone (time->dt, tz);
+       GDateTime *ndt = g_date_time_to_local ((GDateTime*) time);
        str = g_date_time_format (ndt, "%H:%M:%S");
-       g_time_zone_unref (tz);
        g_date_time_unref (ndt);
        return str;
 }
@@ -1604,11 +1582,9 @@ gda_time_to_string_local (GdaTime *time)
 gchar*
 gda_time_to_string_utc (GdaTime *time)
 {
+  GDateTime *ndt = g_date_time_to_utc ((GDateTime*) time);
        gchar *str;
-       GTimeZone *tz = g_time_zone_new_utc ();
-       GDateTime *ndt = g_date_time_to_timezone (time->dt, tz);
        str = g_date_time_format (ndt, "%H:%M:%S%:::z");
-       g_time_zone_unref (tz);
        g_date_time_unref (ndt);
        return str;
 }
@@ -1618,10 +1594,10 @@ gda_time_to_string_utc (GdaTime *time)
  *
  * Change time zone to UTC.
  */
-void
+GdaTime*
 gda_time_to_utc (GdaTime *time)
 {
-  g_date_time_to_utc (time->dt);
+  return (GdaTime*) g_date_time_to_utc ((GDateTime*) time);
 }
 
 /**
@@ -1636,54 +1612,23 @@ gda_time_to_utc (GdaTime *time)
  */
 GdaTime*
 gda_time_new_from_values (gushort hour, gushort minute, gushort second, gulong fraction, glong timezone)
-{
-       GdaTime* time = g_new0 (GdaTime, 1);
-       gda_time_set_from_values (time, hour, minute, second, fraction, timezone);
-       return time;
-}
-
-/**
- * gda_time_set_from_values:
- * @time: a #GdaTime object to set values to
- * @hour: hours
- * @minute: minutes
- * @second: seconds
- * @fraction: fraction of seconds
- * @timezone: timezone in seconds added to UTC
- *
- * Since: 6.0
- */
-void
-gda_time_set_from_values (GdaTime *time, gushort hour, gushort minute, gushort second, gulong fraction, 
glong timezone)
 {
        gdouble seconds = 0.0;
        gchar *sec = g_strdup_printf ("%d.%lu", second, fraction);
        seconds = g_ascii_strtod (sec, NULL);
        g_free (sec);
-       gint h = timezone / 3600;
-       gint m = (timezone - h * 3600) / 60;
-       gint s = (timezone - h * 3600 - m * 60);
-       gint sig = h;
-       if (m < 0) {
-               m = -1 * m;
-       }
-       if (s < 0) {
-               s = -1 * s;
-       }
-       if (h < 0) {
-               h = -1 * h;
-       }
-       gchar *stz = g_strdup_printf ("%s%02d:%02d:%02d", sig < 0 ? "-" : "+", h, m, s);
-       GTimeZone *tz = g_time_zone_new (stz);
-       g_free (stz);
+       GTimeZone *tz = g_time_zone_new_offset (timezone);
 
-       time->dt = g_date_time_new (tz,
+       GdaTime* time = (GdaTime*) g_date_time_new (tz,
                                    1970,
                                    1,
                                    1,
                                    (gint) hour,
                                    (gint) minute,
                                    seconds);
+  g_time_zone_unref (tz);
+
+  return time;
 }
 
 /**
@@ -1696,22 +1641,9 @@ gda_time_set_from_values (GdaTime *time, gushort hour, gushort minute, gushort s
 GdaTime*
 gda_time_new_from_date_time (GDateTime *dt)
 {
-       GdaTime* time = g_new0 (GdaTime, 1);
-       time->dt = g_date_time_add_days (dt, 0);
-       return time;
+       return (GdaTime*) g_date_time_add_days (dt, 0);
 }
 
-/**
- * gda_time_set_from_date_time:
- * @dt: a #GDateTime to get time from
- *
- * Since: 6.0
- */
-void
-gda_time_set_from_date_time (GdaTime *time, GDateTime *dt)
-{
-       time->dt = g_date_time_add_days (dt, 0);
-}
 /**
  * gda_time_get_hour:
  * @time: a #GdaTime value to get hours from
@@ -1722,7 +1654,7 @@ gushort
 gda_time_get_hour (const GdaTime* time)
 {
        g_return_val_if_fail (time != NULL, 0);
-       return (gushort) g_date_time_get_hour (time->dt);
+       return (gushort) g_date_time_get_hour ((GDateTime*) time);
 }
 /**
  * gda_time_set_hour:
@@ -1751,7 +1683,7 @@ gushort
 gda_time_get_minute (const GdaTime* time)
 {
        g_return_val_if_fail (time != NULL, 0);
-       return (gushort) g_date_time_get_minute (time->dt);
+       return (gushort) g_date_time_get_minute ((GDateTime*) time);
 }
 /**
  * gda_time_set_minute:
@@ -1780,7 +1712,7 @@ gushort
 gda_time_get_second (const GdaTime* time)
 {
        g_return_val_if_fail (time != NULL, 0);
-       return (gushort) g_date_time_get_second (time->dt);
+       return (gushort) g_date_time_get_second ((GDateTime*) time);
 }
 /**
  * gda_time_set_second:
@@ -1809,7 +1741,7 @@ gulong
 gda_time_get_fraction (const GdaTime* time)
 {
        g_return_val_if_fail (time != NULL, 0);
-       gdouble v = g_date_time_get_seconds (time->dt) - g_date_time_get_second (time->dt);
+       gdouble v = g_date_time_get_seconds ((GDateTime*) time) - g_date_time_get_second ((GDateTime*) time);
        gchar *str = g_strdup_printf ("%0.6f", v);
        for (int i = 0; i < 2; i++) {
                str[i] = ' ';
@@ -1847,8 +1779,7 @@ glong
 gda_time_get_timezone (const GdaTime* time)
 {
        g_return_val_if_fail (time != NULL, 0);
-       glong tz = (glong) (g_date_time_get_utc_offset (time->dt) / 1000000);
-       return tz;
+  return g_date_time_get_utc_offset ((GDateTime*) time) / 1000000;
 }
 /**
  * gda_time_get_tz:
@@ -1862,7 +1793,7 @@ GTimeZone*
 gda_time_get_tz (const GdaTime* time)
 {
        g_return_val_if_fail (time != NULL, 0);
-       const gchar *stz = g_date_time_get_timezone_abbreviation (time->dt);
+       const gchar *stz = g_date_time_get_timezone_abbreviation ((GDateTime*)time);
        GTimeZone *tz = g_time_zone_new (stz);
        return tz;
 }
@@ -1902,47 +1833,6 @@ gda_time_valid (const GdaTime *time)
        return TRUE;
 }
 
-/**
- * gda_time_change_timezone:
- * @time: a valid #GdaTime
- * @ntz: a new timezone to use, in seconds added to GMT
- *
- * Changes @time's timezone (for example to convert from GMT to another time zone).
- * If @time's current timezone is unset (i.e. equal to %GDA_TIMEZONE_INVALID), then this function simply sets
- * @time's timezone attribute; Otherwise, it adds or removes hours, minutes or seconds to reflect the time 
in the new timezone.
- *
- * Note: the resulting will always be a valid time.
- *
- * Since: 5.2
- */
-void
-gda_time_change_timezone (GdaTime *time, glong ntz)
-{
-       g_return_if_fail (time);
-       g_return_if_fail (gda_time_valid (time));
-
-       gint h = ntz / 3600;
-       gint m = (ntz - h * 3600) / 60;
-       gint s = (ntz - h * 3600 - m * 60);
-       gint sig = h;
-       if (m < 0) {
-               m = -1 * m;
-       }
-       if (s < 0) {
-               s = -1 * s;
-       }
-       if (h < 0) {
-               h = -1 * h;
-       }
-       gchar *stz = g_strdup_printf ("%s%02d:%02d:%02d", sig < 0 ? "-" : "+", h, m, s);
-       GTimeZone *tz = g_time_zone_new (stz);
-       g_free (stz);
-       GDateTime *ndt = time->dt;
-       time->dt = g_date_time_to_timezone (time->dt, tz);
-       g_date_time_unref (ndt);
-}
-
-
 /**
  * gda_time_to_timezone:
  * @time: a valid #GdaTime
@@ -1952,15 +1842,11 @@ gda_time_change_timezone (GdaTime *time, glong ntz)
  *
  * Since: 6.0
  */
-void
+GdaTime*
 gda_time_to_timezone (GdaTime *time, GTimeZone *ntz)
 {
        g_return_if_fail (time);
-       g_return_if_fail (gda_time_valid (time));
-
-       GDateTime *ndt = time->dt;
-       time->dt = g_date_time_to_timezone (time->dt, ntz);
-       g_date_time_unref (ndt);
+       return (GdaTime*) g_date_time_to_timezone ((GDateTime*) time, ntz);
 }
 
 /**
@@ -2805,7 +2691,7 @@ gda_value_stringify (const GValue *value)
                                                        date->year, date->month, date->day);
                }
                else
-                       return g_strdup ("0000-00-00");
+                       return g_strdup ("NULL");
        }
   else if (g_type_is_a (type, GDA_TYPE_TIME)) {
                GdaTime *gts;
@@ -2813,7 +2699,7 @@ gda_value_stringify (const GValue *value)
                if (gts != NULL) {
                        return gda_time_to_string_utc (gts);
                } else {
-                       return "00:00:00+0";
+                       return "NULL";
                }
   }
   else if (g_type_is_a (type, G_TYPE_DATE_TIME)) {
@@ -2973,34 +2859,8 @@ gda_value_differ (const GValue *value1, const GValue *value2)
                t1 = gda_value_get_time (value1);
                t2 = gda_value_get_time (value2);
                if (t1 && t2) {
-                       gchar *stz = g_strdup_printf ("%ld", gda_time_get_timezone (t1));
-                       gchar *sec = g_strdup_printf ("%u.%ld", gda_time_get_minute (t1), 
gda_time_get_fraction (t1));
-                       gdouble seconds = g_strtod (sec, NULL);
-                       GTimeZone *tz = g_time_zone_new (stz);
-                       GDateTime *dt1 = g_date_time_new (tz, 1970, 1, 1,
-                                                                                                             
                                                  gda_time_get_hour (t1),
-                                                                                                             
                                                  gda_time_get_minute (t1),
-                                                                                                             
                                                  seconds);
-                       g_free (stz);
-                       g_free (sec);
-                       g_time_zone_unref (tz);
-                       stz = g_strdup_printf ("%ld", gda_time_get_timezone (t1));
-                       sec = g_strdup_printf ("%u.%ld", gda_time_get_minute (t1), gda_time_get_fraction 
(t1));
-                       seconds = g_strtod (sec, NULL);
-                       tz = g_time_zone_new (stz);
-                       GDateTime *dt2 = g_date_time_new (tz, 1970, 1, 1,
-                                                                                                             
                                                  gda_time_get_hour (t1),
-                                                                                                             
                                                  gda_time_get_minute (t1),
-                                                                                                             
                                                  seconds);
-                       g_free (stz);
-                       g_free (sec);
-                       g_time_zone_unref (tz);
-                       gint res = (gint) g_date_time_difference (dt1, dt2);
-                       g_date_time_unref (dt1);
-                       g_date_time_unref (dt2);
-                       return res;
+      return g_date_time_difference ((GDateTime*) t1,(GDateTime*) t2) != 0 ? 1 : 0;
     }
-                       return bcmp (t1, t2, sizeof (GdaTime));
                return 1;
        }
 
@@ -3289,13 +3149,7 @@ gda_value_compare (const GValue *value1, const GValue *value2)
                t1 = gda_value_get_time (value1);
                t2 = gda_value_get_time (value2);
                if (t1 && t2)
-                       return memcmp (t1, t2, sizeof (GdaTime));
-               else if (t1)
-                       return 1;
-               else if (t2)
-                       return -1;
-               else
-                       return 0;
+                       return g_date_time_compare ((GDateTime*) t1, (GDateTime*) t2);
        }
 
        else if (type == G_TYPE_DATE_TIME) {
diff --git a/libgda/gda-value.h b/libgda/gda-value.h
index c139e1403..ba202d50e 100644
--- a/libgda/gda-value.h
+++ b/libgda/gda-value.h
@@ -95,7 +95,7 @@ void                              gda_numeric_free (GdaNumeric *numeric);
  *
  * Represents a time information.
  */
-typedef struct _GdaTime GdaTime;
+typedef struct GDateTime GdaTime;
 
 GType                             gda_time_get_type (void) G_GNUC_CONST;
 GdaTime*                          gda_time_new (void);
@@ -104,8 +104,6 @@ GdaTime*                          gda_time_new_from_values (gushort hour, gushor
 GdaTime*                          gda_time_copy (const GdaTime* time);
 void                              gda_time_free (GdaTime* time);
 
-void                              gda_time_set_from_date_time (GdaTime *time, GDateTime *dt);
-void                              gda_time_set_from_values (GdaTime *time, gushort hour, gushort minute, 
gushort second, gulong fraction, glong timezone);
 gushort                           gda_time_get_hour (const GdaTime* time);
 void                              gda_time_set_hour (GdaTime* time, gushort hour);
 gushort                           gda_time_get_minute (const GdaTime* time);
@@ -116,12 +114,10 @@ gulong                            gda_time_get_fraction (const GdaTime *time);
 void                              gda_time_set_fraction (GdaTime* time, gulong fraction);
 GTimeZone*                        gda_time_get_tz (const GdaTime *time);
 glong                             gda_time_get_timezone (const GdaTime *time);
-void                              gda_time_set_timezone (GdaTime* time, glong timezone);
 
 gboolean                          gda_time_valid (const GdaTime *time);
-void                              gda_time_change_timezone (GdaTime *time, glong ntz);
-void                              gda_time_to_timezone (GdaTime *time, GTimeZone *ntz);
-void                              gda_time_to_utc (GdaTime *time);
+GdaTime                          *gda_time_to_timezone (GdaTime *time, GTimeZone *ntz);
+GdaTime                          *gda_time_to_utc (GdaTime *time);
 gchar*                            gda_time_to_string (GdaTime *time);
 gchar*                            gda_time_to_string_local (GdaTime *time);
 gchar*                            gda_time_to_string_utc (GdaTime *time);
diff --git a/libgda/handlers/gda-handler-time.c b/libgda/handlers/gda-handler-time.c
index 6a41f0810..312ba1fea 100644
--- a/libgda/handlers/gda-handler-time.c
+++ b/libgda/handlers/gda-handler-time.c
@@ -758,7 +758,7 @@ static GDateTime * make_timestamp (GdaHandlerTime *hdl,
                                const gchar *value, LocaleSetting *locale);
 static gboolean make_date (GdaHandlerTime *hdl, GDate *date, const gchar *value,
                           LocaleSetting *locale, const gchar **out_endptr);
-static gboolean make_time (GdaHandlerTime *hdl, GdaTime *timegda, const gchar *value);
+static GdaTime * make_time (GdaHandlerTime *hdl, const gchar *value);
 static GValue *
 gda_handler_time_get_value_from_locale (GdaDataHandler *iface, const gchar *sql, 
                                        GType type, LocaleSetting *locale)
@@ -777,12 +777,11 @@ gda_handler_time_get_value_from_locale (GdaDataHandler *iface, const gchar *sql,
                }
        }
        else if (type == GDA_TYPE_TIME) {
-               GdaTime* timegda = gda_time_new ();
-               if (make_time (hdl, timegda, sql)) {
+               GdaTime* timegda =make_time (hdl, sql);
+               if (timegda != NULL) {
                        value = g_value_init (g_new0 (GValue, 1), GDA_TYPE_TIME);
-                       gda_value_set_time (value, timegda);
+                       g_value_take_boxed (value, timegda);
                }
-               gda_time_free (timegda);
        }
        else if (g_type_is_a (type, G_TYPE_DATE_TIME)) {
                GDateTime* timestamp = make_timestamp (hdl, sql, locale);
@@ -806,52 +805,10 @@ gda_handler_time_get_value_from_locale (GdaDataHandler *iface, const gchar *sql,
 static GDateTime*
 make_timestamp (GdaHandlerTime *hdl, const gchar *value, LocaleSetting *locale)
 {
-       gboolean retval;
-       const gchar *end_ptr;
-       GDate vdate;
-       GdaTime* vtime;
-       vtime = gda_time_new ();
-       gda_time_set_timezone (vtime, GDA_TIMEZONE_INVALID);
-
-       retval = make_date (hdl, &vdate, value, locale, &end_ptr);
-
-       if (retval) {
-               if (*end_ptr != ' ' && *end_ptr != 'T')
-                       return NULL;
-               else
-                       if (!make_time (hdl, vtime, end_ptr + 1))
-                               return NULL;
-       }
-       gchar *stz;
-       gint ts = gda_time_get_timezone (vtime);
-       if (ts < 0) ts *= -1;
-       gint h = ts/60/60;
-       gint m = ts/60 - h * 60;
-       gint s = ts - h * 60 * 60 - m * 60;
-       stz = g_strdup_printf ("%s%02d:%02d:%02d",
-                                                                                                             
                  gda_time_get_timezone (vtime) >= 0 ? "+" : "-",
-                                                                                                             
                  h, m, s);
-  g_print ("STR for TZ: %s\n" , stz);
-       GTimeZone* tz = g_time_zone_new (stz);
-       g_free (stz);
-       if (tz == NULL)
-               return NULL;
-       gdouble seconds;
-       seconds = (gdouble) (gda_time_get_second (vtime) + gda_time_get_fraction (vtime) / 1000000.0);
-       g_print ("Fraction: %ld, %f\n", gda_time_get_fraction (vtime), gda_time_get_fraction (vtime) / 
1000000.0);
-       g_print ("Seconds to set %lf\n", seconds);
-       g_print ("TZ: %d\n", g_time_zone_get_offset (tz, 0));
-       GDateTime *dt = g_date_time_new (tz,
-                                                                                                             
                          g_date_get_year (&vdate),
-                                                                                                             
                          g_date_get_month (&vdate),
-                                                                                                             
                          g_date_get_day (&vdate),
-                                                                                                             
                          gda_time_get_hour (vtime),
-                                                                                                             
                          gda_time_get_minute (vtime),
-                                                                                                             
                          seconds);
-       gchar *tss = g_date_time_format (dt, "%FT%H%:%M:%S:::z");
-       g_print ("String: %s\n", tss);
-       g_free (tss);
-       return (GDateTime*) dt;
+  GTimeZone *default_tz = g_time_zone_new_local ();
+       GDateTime* dt = g_date_time_new_from_iso8601 (value, default_tz);
+  g_time_zone_unref (default_tz);
+  return dt;
 }
 
 static gboolean
@@ -997,13 +954,14 @@ make_date (G_GNUC_UNUSED GdaHandlerTime *hdl, GDate *date, const gchar *value,
  *
  * Also works if there is only 0 or 1 digit instead of 2
  */
-static gboolean
-make_time (G_GNUC_UNUSED GdaHandlerTime *hdl, GdaTime *timegda, const gchar *value)
+static GdaTime *
+make_time (G_GNUC_UNUSED GdaHandlerTime *hdl, const gchar *value)
 {
-       if (gda_parse_iso8601_time (timegda, value))
-               return TRUE;
-       else
-               return gda_parse_formatted_time (timegda, value, 0);
+  GdaTime *ret = NULL;
+       ret = gda_parse_iso8601_time (value);
+  if (ret == NULL)
+               return gda_parse_formatted_time (value, 0);
+  return ret;
 }
 
 
@@ -1013,7 +971,7 @@ gda_handler_time_get_sane_init_value (G_GNUC_UNUSED GdaDataHandler *iface, GType
        GValue *value = NULL;
        GDateTime *gdate;
 
-       gdate = g_date_time_new_now_local ();
+       gdate = g_date_time_new_now_utc ();
 
        if (type == G_TYPE_DATE) {
                GDate *date = g_date_new_dmy ((GDateDay) g_date_time_get_day_of_month (gdate),
@@ -1023,31 +981,17 @@ gda_handler_time_get_sane_init_value (G_GNUC_UNUSED GdaDataHandler *iface, GType
                g_value_take_boxed (value, date);
        }
        else if (type == GDA_TYPE_TIME) {
-               GdaTime* gtime;
-
-               gtime = gda_time_new_from_values (
-                            g_date_time_get_hour (gdate),
-                            g_date_time_get_minute (gdate),
-                            g_date_time_get_second (gdate),
-                            g_date_time_get_seconds (gdate) - (gdouble) g_date_time_get_second (gdate),
-                            (glong) g_date_time_get_utc_offset (gdate));
-
                value = g_value_init (g_new0 (GValue, 1), GDA_TYPE_TIME);
-               gda_value_set_time (value, gtime);
+               g_value_set_boxed (value, gdate);
        }
        else if (g_type_is_a (type, G_TYPE_DATE_TIME)) {
-               GDateTime* gts = g_date_time_new_now_utc ();
-
-               if (gts != NULL) {
-      value = g_value_init (g_new0 (GValue, 1), G_TYPE_DATE_TIME);
-                 g_value_set_boxed (value, gts);
-      g_date_time_unref (gts);
-    } else {
-      g_warning (_("Invalid values from statement to create a timestamp"));
-    }
+    value = g_value_init (g_new0 (GValue, 1), G_TYPE_DATE_TIME);
+         g_value_set_boxed (value, gdate);
        }
        else
-               g_assert_not_reached ();
+               value = gda_value_new_null ();
+
+  g_date_time_unref (gdate);
 
        return value;
 }
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index 6edf91e2d..3dae4199e 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -3664,31 +3664,13 @@ gda_sqlite_provider_statement_execute (GdaServerProvider *provider, GdaConnectio
                                                          gda_binary_get_data (bin), gda_binary_get_size 
(bin), SQLITE_TRANSIENT);
                }
                else if (G_VALUE_TYPE (value) == GDA_TYPE_TIME) {
-                       GString *string;
+                       gchar *string;
                        GdaTime *gtime;
-                       gboolean tofree = FALSE;
 
                        gtime = (GdaTime *) gda_value_get_time (value);
+      string = gda_time_to_string_utc (gtime);
 
-                       string = g_string_new ("");
-                       if (gda_time_get_timezone (gtime) != GDA_TIMEZONE_INVALID) {
-                               /* SQLite cant' store timezone information, so if timezone information is
-                                * provided, we do our best and convert it to GMT */
-                               gtime = gda_time_copy (gtime);
-                               tofree = TRUE;
-                               gda_time_change_timezone (gtime, 0);
-                       }
-
-                       g_string_append_printf (string, "%02u:%02u:%02u",
-                                               gda_time_get_hour (gtime),
-                                               gda_time_get_minute (gtime),
-                                               gda_time_get_second (gtime));
-                       if (gda_time_get_fraction (gtime) > 0)
-                               g_string_append_printf (string, ".%lu", gda_time_get_fraction (gtime));
-
-                       if (tofree)
-                               gda_time_free (gtime);
-                       SQLITE3_CALL (prov, sqlite3_bind_text) (_gda_sqlite_pstmt_get_stmt (ps), i, 
g_string_free (string, FALSE), -1, g_free);
+                       SQLITE3_CALL (prov, sqlite3_bind_text) (_gda_sqlite_pstmt_get_stmt (ps), i, string, 
-1, g_free);
                }
                else if (G_VALUE_TYPE (value) == G_TYPE_DATE) {
                        gchar *str;
diff --git a/libgda/sqlite/gda-sqlite-recordset.c b/libgda/sqlite/gda-sqlite-recordset.c
index f81dd17a7..1015f8be8 100644
--- a/libgda/sqlite/gda-sqlite-recordset.c
+++ b/libgda/sqlite/gda-sqlite-recordset.c
@@ -527,22 +527,21 @@ fetch_next_sqlite_row (GdaSqliteRecordset *model, gboolean do_store, GError **er
                                                g_value_set_boxed (value, &date);
                                }
                                else if (type == GDA_TYPE_TIME) {
-                                       GdaTime* timegda = gda_time_new ();
-                                       if (!gda_parse_iso8601_time (timegda,
-                                                                    (gchar *) SQLITE3_CALL (prov, 
sqlite3_column_text) (_gda_sqlite_pstmt_get_stmt (ps),
-                                                                                                   
real_col))) {
+          const gchar *str = (const gchar *) SQLITE3_CALL (prov, sqlite3_column_text) 
(_gda_sqlite_pstmt_get_stmt (ps),
+                                                                                                   real_col);
+                                       GdaTime* timegda = gda_parse_iso8601_time (
+                            str);
+                                       if (timegda == NULL) {
                                                GError *lerror = NULL;
                                                g_set_error (&lerror, GDA_SERVER_PROVIDER_ERROR,
                                                             GDA_SERVER_PROVIDER_DATA_ERROR,
-                                                            _("Invalid time '%s' (time format should be 
HH:MM:SS[.ms])"), 
+                                                            _("Invalid time '%s' (time format should be 
HH:MM:SS[.ms][+HH:mm])"),
                                                             (gchar *) SQLITE3_CALL (prov, 
sqlite3_column_text) (_gda_sqlite_pstmt_get_stmt (ps), real_col));
                                                gda_row_invalidate_value_e (prow, value, lerror);
                                        }
                                        else {
-                                               gda_time_to_utc (timegda);
-                                               g_value_set_boxed (value, timegda);
+                                               g_value_take_boxed (value, timegda);
                                        }
-                                       gda_time_free (timegda);
                                }
                                else if (g_type_is_a (type, G_TYPE_DATE_TIME)) {
                                        GDateTime* timestamp = gda_parse_iso8601_timestamp (
@@ -557,8 +556,7 @@ fetch_next_sqlite_row (GdaSqliteRecordset *model, gboolean do_store, GError **er
                                                gda_row_invalidate_value_e (prow, value, lerror);
                                        }
                                        else {
-                                               g_value_set_boxed (value, timestamp);
-                                         g_date_time_unref (timestamp);
+                                               g_value_take_boxed (value, timestamp);
                                        }
                                }
                                else if (type == G_TYPE_CHAR) {
diff --git a/libgda/sqlite/virtual/gda-vconnection-hub.c b/libgda/sqlite/virtual/gda-vconnection-hub.c
index a6de5be17..c25a7b2ed 100644
--- a/libgda/sqlite/virtual/gda-vconnection-hub.c
+++ b/libgda/sqlite/virtual/gda-vconnection-hub.c
@@ -660,8 +660,8 @@ create_value_from_sqlite3_gvalue (GType type, GValue *svalue, GError **error)
                if (G_VALUE_TYPE (svalue) != G_TYPE_STRING)
                        allok = FALSE;
                else {
-                       GdaTime* timegda = gda_time_new ();
-                       if (!gda_parse_iso8601_time (timegda, g_value_get_string (svalue))) {
+                       GdaTime* timegda = gda_parse_iso8601_time (g_value_get_string (svalue));
+                       if (!timegda) {
                                g_set_error (error, GDA_SERVER_PROVIDER_ERROR,
                                             GDA_SERVER_PROVIDER_DATA_ERROR,
                                             _("Invalid time '%s' (time format should be HH:MM:SS[.ms])"),
diff --git a/providers/mysql/gda-mysql-provider.c b/providers/mysql/gda-mysql-provider.c
index 3c72ffa20..b49bd2ded 100644
--- a/providers/mysql/gda-mysql-provider.c
+++ b/providers/mysql/gda-mysql-provider.c
@@ -2388,24 +2388,16 @@ gda_mysql_provider_statement_execute (GdaServerProvider               *provider,
                                mysql_bind_param[i].is_null = (my_bool*)1;
                        }
                        else {
-                               gboolean tofree = FALSE;
-                               if (gda_time_get_timezone (ts) != GDA_TIMEZONE_INVALID) {
-                                       /* MySQL does not store timezone information, so if timezone 
information is
-                                        * provided, we do our best and convert it to GMT */
-                                       ts = gda_time_copy (ts);
-                                       tofree = TRUE;
-                                       gda_time_change_timezone (ts, 0);
-                               }
+        GdaTime *nts = gda_time_to_utc (ts);
 
                                MYSQL_TIME *mtime;
                                mtime = g_new0 (MYSQL_TIME, 1);
                                mem_to_free = g_slist_prepend (mem_to_free, mtime);
-                               mtime->hour = gda_time_get_hour (ts);
-                               mtime->minute = gda_time_get_minute (ts);
-                               mtime->second = gda_time_get_second (ts);
-                               mtime->second_part = gda_time_get_fraction (ts);
-                               if (tofree)
-                                       gda_time_free (ts);
+                               mtime->hour = gda_time_get_hour (nts);
+                               mtime->minute = gda_time_get_minute (nts);
+                               mtime->second = gda_time_get_second (nts);
+                               mtime->second_part = gda_time_get_fraction (nts);
+                               gda_time_free (nts);
 
                                mysql_bind_param[i].buffer_type= MYSQL_TYPE_TIME;
                                mysql_bind_param[i].buffer= (char *)mtime;
diff --git a/providers/postgres/gda-postgres-provider.c b/providers/postgres/gda-postgres-provider.c
index 046bde131..e325f6763 100644
--- a/providers/postgres/gda-postgres-provider.c
+++ b/providers/postgres/gda-postgres-provider.c
@@ -2208,21 +2208,15 @@ gda_postgres_provider_statement_execute (GdaServerProvider *provider, GdaConnect
                        g_assert (timdh);
 
                        GdaTime *gdatime;
-                       gdatime = (GdaTime*) gda_value_get_time (value);
-                       if (gda_time_get_timezone (gdatime) != GDA_TIMEZONE_INVALID) {
-                               /* PostgreSQL does not store timezone information, so if timezone information 
is
-                                * provided, we do our best and convert it to GMT */
-                               gdatime = gda_time_copy (gdatime);
-                               gda_time_change_timezone (gdatime, 0);
-                               GValue *rv;
-                               rv = gda_value_new (GDA_TYPE_TIME);
-                               gda_value_set_time (rv, gdatime);
-                               gda_time_free (gdatime);
-                               param_values [i] = gda_handler_time_get_no_locale_str_from_value (timdh, rv);
-                               gda_value_free (rv);
-                       }
-                       else
-                               param_values [i] = gda_handler_time_get_no_locale_str_from_value (timdh, 
value);
+      GdaTime *ngdatime;
+
+                       gdatime = g_value_get_boxed (value);
+                       GValue *rv;
+      ngdatime = gda_time_to_utc (gdatime);
+                       rv = gda_value_new (GDA_TYPE_TIME);
+      g_value_take_boxed (rv, ngdatime);
+                       param_values [i] = gda_handler_time_get_no_locale_str_from_value (timdh, rv);
+                       gda_value_free (rv);
                }
                else {
                        GdaDataHandler *dh;
diff --git a/providers/postgres/gda-postgres-recordset.c b/providers/postgres/gda-postgres-recordset.c
index d40dcc732..632a89bcc 100644
--- a/providers/postgres/gda-postgres-recordset.c
+++ b/providers/postgres/gda-postgres-recordset.c
@@ -612,19 +612,16 @@ set_value (GdaConnection *cnc, GdaRow *row, GValue *value, GType type, const gch
                                     "%s", _("Internal error"));
        }
        else if (type == GDA_TYPE_TIME) {
-               GdaTime* timegda = gda_time_new ();
-               if (!gda_parse_iso8601_time (timegda, thevalue)) {
+               GdaTime* timegda = gda_parse_iso8601_time (thevalue);
+               if (timegda == NULL) {
                        gda_row_invalidate_value (row, value); 
                        g_set_error (error, GDA_SERVER_PROVIDER_ERROR,
                                     GDA_SERVER_PROVIDER_DATA_ERROR,
                                     _("Invalid time '%s' (time format should be HH:MM:SS[.ms])"), thevalue);
                }
                else {
-                       if (gda_time_get_timezone (timegda) == GDA_TIMEZONE_INVALID)
-                               gda_time_set_timezone (timegda, 0); /* set to GMT */
-                       gda_value_set_time (value, timegda);
+                       g_value_take_boxed (value, timegda);
                }
-               gda_time_free (timegda);
        }
        else if (type == G_TYPE_INT64)
                g_value_set_int64 (value, atoll (thevalue));
diff --git a/tests/data-models/check_vcnc.c b/tests/data-models/check_vcnc.c
index 6efd8fa89..03bbd721b 100644
--- a/tests/data-models/check_vcnc.c
+++ b/tests/data-models/check_vcnc.c
@@ -109,16 +109,18 @@ test1 (Data *data) {
        g_message ("Add data models to virtual connection: city");
        if (!gda_vconnection_data_model_add_model (GDA_VCONNECTION_DATA_MODEL (virtual),
                                                   city_model, "city", &error)) {
-               g_message ("Add city model error: %s", error->message);
-               g_error_free (error);
+               g_message ("Add city model error: %s", error && error->message ? error->message : "No 
detail");
+    data->fails += 1;
+               g_clear_error (&error);
                g_main_loop_quit (data->loop);
                return G_SOURCE_REMOVE;
        }
        g_message ("Add data models to virtual connection: country");
        if (!gda_vconnection_data_model_add_model (GDA_VCONNECTION_DATA_MODEL (virtual),
                                                   country_model, "country", &error)) {
-               g_message ("Add country model error: %s", error->message);
-               g_error_free (error);
+               g_message ("Add country model error: %s", error && error->message ? error->message : "No 
detail");
+    data->fails += 1;
+               g_clear_error (&error);
                g_main_loop_quit (data->loop);
                return G_SOURCE_REMOVE;
        }
@@ -126,7 +128,8 @@ test1 (Data *data) {
        GdaDataModel *datamodel;
        datamodel = gda_connection_execute_select_command (virtual, "SELECT * FROM city", &error);
        if (datamodel == NULL) {
-               g_message ("Select data from city model error: %s", error->message);
+               g_message ("Select data from city model error: %s", error && error->message ? error->message 
: "No detail");
+    data->fails += 1;
                g_clear_error (&error);
                g_main_loop_quit (data->loop);
                return G_SOURCE_REMOVE;
@@ -139,7 +142,8 @@ test1 (Data *data) {
 
        datamodel = gda_connection_execute_select_command (virtual, "SELECT * FROM country", &error);
        if (datamodel == NULL) {
-               g_message ("Select data from city model error: %s", error->message);
+               g_message ("Select data from city model error: %s", error && error->message ? error->message 
: "No detail");
+    data->fails += 1;
                g_clear_error (&error);
                g_main_loop_quit (data->loop);
                return G_SOURCE_REMOVE;
@@ -153,8 +157,9 @@ test1 (Data *data) {
        g_message ("Open SQLite connection for outputs");
        out_cnc = open_destination_connection (data, &error);
        if (out_cnc == NULL) {
-               g_message ("Error opening destination %s", error->message);
-               g_error_free (error);
+               g_message ("Error opening destination %s", error && error->message ? error->message : "No 
detail");
+    data->fails += 1;
+               g_clear_error (&error);
                g_main_loop_quit (data->loop);
                return G_SOURCE_REMOVE;
        }
@@ -163,47 +168,52 @@ test1 (Data *data) {
        g_message ("Add output connection to virtual connection hub");
        if (!gda_vconnection_hub_add (GDA_VCONNECTION_HUB (virtual), out_cnc, "out", &error)) {
                g_message ("Could not add connection to virtual connection: %s",
-                       error->message);
-               g_error_free (error);
-                data->fails += 1;
-                g_main_loop_quit (data->loop);
-                return G_SOURCE_REMOVE;
-        }
+                       error && error->message ? error->message : "No detail");
+               g_clear_error (&error);
+    data->fails += 1;
+    g_main_loop_quit (data->loop);
+    return G_SOURCE_REMOVE;
+  }
 
        g_message ("Update/Delete check");
        if (!check_update_delete (virtual, &error)) {
-               g_message ("Error at update-delete: %s", error->message);
-               g_error_free (error);
+               g_message ("Error at update-delete: %s", error && error->message ? error->message : "No 
detail");
+    data->fails += 1;
+               g_clear_error (&error);
                g_main_loop_quit (data->loop);
                return G_SOURCE_REMOVE;
        }
 
        g_message ("*** Copying data into 'countries' virtual table...\n");
        if (!assert_run_sql_non_select (virtual, "INSERT INTO out.countries SELECT * FROM country", NULL, 
&error)) {
-               g_message ("Error: Check Siumultaneos select random: %s", error->message);
-               g_error_free (error);
+               g_message ("Error: Check Siumultaneos select random: %s", error && error->message ? 
error->message : "No detail");
+    data->fails += 1;
+               g_clear_error (&error);
                g_main_loop_quit (data->loop);
                return G_SOURCE_REMOVE;
        }
 
        g_message ("Check simultaneous select ramdom");
        if (!check_simultanous_select_random (virtual, &error)) {
-               g_message ("Error: Check Siumultaneos select random: %s", error->message);
-               g_error_free (error);
+               g_message ("Error: Check Siumultaneos select random: %s", error && error->message ? 
error->message : "No detail");
+    data->fails += 1;
+               g_clear_error (&error);
                g_main_loop_quit (data->loop);
                return G_SOURCE_REMOVE;
        }
        g_message ("Check simultaneous select forward");
        if (!check_simultanous_select_forward (virtual, &error)) {
-               g_message ("Error: Check Simultaneos select forward: %s", error->message);
-               g_error_free (error);
+               g_message ("Error: Check Simultaneos select forward: %s", error && error->message ? 
error->message : "No detail");
+    data->fails += 1;
+               g_clear_error (&error);
                g_main_loop_quit (data->loop);
                return G_SOURCE_REMOVE;
        }
 
        if (!check_date (virtual, &error)) {
-               g_message ("Error: Check Date: %s", error->message);
-               g_error_free (error);
+               g_message ("Error: Check Date: %s", error && error->message ? error->message : "No detail");
+    data->fails += 1;
+               g_clear_error (&error);
                g_main_loop_quit (data->loop);
                return G_SOURCE_REMOVE;
        }
@@ -212,17 +222,19 @@ test1 (Data *data) {
        check_threads_select_random (virtual);
 
 
-        if (! gda_connection_close (virtual, &error)) {
-               g_message ("gda_connection_close(virtual) error: %s", error->message);
-                data->fails += 1;
-                g_main_loop_quit (data->loop);
-                return G_SOURCE_REMOVE;
+  if (! gda_connection_close (virtual, &error)) {
+               g_message ("gda_connection_close(virtual) error: %s", error && error->message ? 
error->message : "No detail");
+               g_clear_error (&error);
+    data->fails += 1;
+    g_main_loop_quit (data->loop);
+    return G_SOURCE_REMOVE;
        }
-        if (! gda_connection_close (out_cnc, &error)) {
-               g_message ("gda_connection_close(out_cnc) error: %s", error->message);
-                data->fails += 1;
-                g_main_loop_quit (data->loop);
-                return G_SOURCE_REMOVE;
+  if (! gda_connection_close (out_cnc, &error)) {
+               g_message ("gda_connection_close(out_cnc) error: %s", error && error->message ? 
error->message : "No detail");
+               g_clear_error (&error);
+    data->fails += 1;
+    g_main_loop_quit (data->loop);
+    return G_SOURCE_REMOVE;
   }
   g_main_loop_quit (data->loop);
   return G_SOURCE_REMOVE;
@@ -790,37 +802,37 @@ check_date (GdaConnection *virtual, GError **error)
        const GValue *cvalue, *exp;
        cvalue = gda_data_model_get_value_at (model, 0, 0, error);
        if (! cvalue) {
-               g_message ("Could not get timestamp value");
+               g_warning ("Could not get timestamp value");
                return FALSE;
        }
        exp = gda_set_get_holder_value (set, "ts");
        if (gda_value_differ (cvalue, exp)) {
-               g_message ("Expected value '%s', got '%s'\n",
-                        gda_value_stringify (exp), gda_value_stringify (cvalue));
+               g_warning ("Expected Timestamp value '%s', got '%s'\n",
+                   gda_value_stringify (exp), gda_value_stringify (cvalue));
                return FALSE;
        }
 
        cvalue = gda_data_model_get_value_at (model, 1, 0, error);
        if (! cvalue) {
-               g_message ("Could not get timestamp value");
-                return FALSE;
+               g_warning ("Could not get timestamp value");
+    return FALSE;
        }
        exp = gda_set_get_holder_value (set, "adate");
        if (gda_value_differ (cvalue, exp)) {
-               g_message ("Expected value '%s', got '%s'\n",
-                        gda_value_stringify (exp), gda_value_stringify (cvalue));
+               g_warning ("Expected Date value '%s', got '%s'\n",
+                   gda_value_stringify (exp), gda_value_stringify (cvalue));
                return FALSE;
        }
 
        cvalue = gda_data_model_get_value_at (model, 2, 0, error);
        if (! cvalue) {
-               g_message ("Could not get timestamp value");
-                return FALSE;
+               g_warning ("Could not get timestamp value");
+    return FALSE;
        }
        exp = gda_set_get_holder_value (set, "atime");
        if (gda_value_differ (cvalue, exp)) {
-               g_message ("Expected value '%s', got '%s'\n",
-                        gda_value_stringify (exp), gda_value_stringify (cvalue));
+               g_warning ("Expected Time value '%s', got '%s'\n",
+                   gda_value_stringify (exp), gda_value_stringify (cvalue));
                return FALSE;
        }
 
diff --git a/tests/test-input-parsers.c b/tests/test-input-parsers.c
index 6ad4279d2..51f8b3366 100644
--- a/tests/test-input-parsers.c
+++ b/tests/test-input-parsers.c
@@ -160,9 +160,10 @@ test_parse_iso8601_time (void)
 
        for (i = 0; i < sizeof (timedata) / sizeof (TestTime); i++) {
                TestTime td = timedata[i];
-               GdaTime* time = gda_time_new ();
+               GdaTime* time = NULL;
     g_print ("Time to parse: %s\n", td.in_string);
-    g_assert (gda_parse_iso8601_time (time, td.in_string) == td.exp_retval);
+    time = gda_parse_iso8601_time (td.in_string);
+    g_assert ((time != NULL) == td.exp_retval);
     if (!td.exp_retval)
       continue;
                g_print ("test_parse_iso8601_time: result for gda_parse_iso8601_time (\"%s\"):\n"
@@ -302,14 +303,12 @@ TestTime timedata2[] = {
        {"12 0000Z",FALSE, 12, 0, 0, 0, 0},
        {"12 0000Z",FALSE, 12, 0, 0, 0, 0},
        {"1201 00Z",FALSE, 12, 1, 0, 0, 0},
-       {"120102 Z",TRUE, 12, 1, 2, 0, 0},
-       {"120102.Z",TRUE, 12, 1, 2, 0, 0},
-       {"120102:Z",TRUE, 12, 1, 2, 0, 0},
+       {"120102Z",TRUE, 12, 1, 2, 0, 0},
        {"120102.123Z",TRUE, 12, 1, 2, 123000, 0},
-       {"120102-2",TRUE, 12, 1, 2, 0, -2l*60*60},
+       {"120102-02",TRUE, 12, 1, 2, 0, -2l*60*60},
        {"120102+11",TRUE, 12, 1, 2, 0, 11l*60*60},
        {"120102.1234+11",TRUE, 12, 1, 2, 123400, 11l*60*60},
-       {"120102.123456-3",TRUE, 12, 1, 2, 123456, -3l*60*60},
+       {"120102.123456-03",TRUE, 12, 1, 2, 123456, -3l*60*60},
 };
 
 static gboolean



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