[libgda: 1/2] Clean up after GdaTimeStamp



commit efb9a800b00a84f8708ef6bff7bf009b43df133b
Author: Pavlo Solntsev <p sun fun gmail com>
Date:   Tue Jul 17 02:43:45 2018 +0000

    Clean up after GdaTimeStamp

 doc/C/libgda-sections.txt                        | 12 +---
 doc/C/libgda.types.in                            |  1 -
 libgda-ui/data-entries/gdaui-entry-common-time.c |  2 +-
 libgda/gda-util.c                                | 12 ++--
 libgda/gda-util.h                                |  2 +
 libgda/gda-value.c                               | 82 +++++-------------------
 libgda/gda-value.h                               |  6 +-
 libgda/libgda.symbols                            |  1 -
 tests/providers/prov-test-common.c               |  2 +-
 tests/test-input-parsers.c                       | 28 ++++----
 10 files changed, 43 insertions(+), 105 deletions(-)
---
diff --git a/doc/C/libgda-sections.txt b/doc/C/libgda-sections.txt
index 8dc011d68..4899bbafa 100644
--- a/doc/C/libgda-sections.txt
+++ b/doc/C/libgda-sections.txt
@@ -899,8 +899,6 @@ GDA_TYPE_USHORT
 GDA_VALUE_HOLDS_USHORT
 GDA_TYPE_TIME
 GDA_VALUE_HOLDS_TIME
-GDA_TYPE_TIMESTAMP
-GDA_VALUE_HOLDS_TIMESTAMP
 gda_value_new_null
 gda_value_set_null
 gda_value_new_default
@@ -981,15 +979,8 @@ gda_time_change_timezone
 gda_value_get_time
 gda_value_set_time
 gda_value_new_time_from_timet
-<SUBSECTION>
-GdaTimestamp
-gda_timestamp_copy
-gda_timestamp_free
-gda_timestamp_valid
-gda_timestamp_change_timezone
-gda_value_get_timestamp
-gda_value_set_timestamp
 gda_value_new_timestamp_from_timet
+gda_value_new_date_time_from_timet
 <SUBSECTION>
 gda_value_get_short
 gda_value_set_short
@@ -1001,7 +992,6 @@ gda_binary_get_type
 gda_geometric_point_get_type
 gda_numeric_get_type
 gda_time_get_type
-gda_timestamp_get_type
 </SECTION>
 
 <SECTION>
diff --git a/doc/C/libgda.types.in b/doc/C/libgda.types.in
index 9348ce243..1d548afe1 100644
--- a/doc/C/libgda.types.in
+++ b/doc/C/libgda.types.in
@@ -42,7 +42,6 @@ gda_binary_get_type
 gda_geometric_point_get_type
 gda_numeric_get_type
 gda_time_get_type
-gda_timestamp_get_type
 gda_virtual_provider_get_type
 gda_vprovider_data_model_get_type
 gda_vprovider_hub_get_type
diff --git a/libgda-ui/data-entries/gdaui-entry-common-time.c 
b/libgda-ui/data-entries/gdaui-entry-common-time.c
index 03341da9a..8234030d3 100644
--- a/libgda-ui/data-entries/gdaui-entry-common-time.c
+++ b/libgda-ui/data-entries/gdaui-entry-common-time.c
@@ -899,7 +899,7 @@ entry_insert_func (G_GNUC_UNUSED GdauiFormattedEntry *fentry, gunichar insert_ch
                        //gchar *str;
                        //GdauiEntryCommonTime *mgtim = GDAUI_ENTRY_COMMON_TIME (data);
                        //str = gdaui_formatted_entry_get_text (GDAUI_FORMATTED_ENTRY (mgtim->priv->entry));
-                       tsvalue = gda_value_new_timestamp_from_timet (time (NULL));
+                       tsvalue = gda_value_new_date_time_from_timet (time (NULL));
                        real_set_value (GDAUI_ENTRY_WRAPPER (data), tsvalue);
                        gda_value_free (tsvalue);
                        //if (str && g_ascii_isdigit (*str))
diff --git a/libgda/gda-util.c b/libgda/gda-util.c
index c05b3c691..6387c8303 100644
--- a/libgda/gda-util.c
+++ b/libgda/gda-util.c
@@ -14,6 +14,7 @@
  * Copyright (C) 2010 David King <davidk openismus com>
  * Copyright (C) 2010 Jonh Wendell <jwendell gnome org>
  * Copyright (C) 2011-2018 Daniel Espinosa <esodan gmail com>
+ * Copyright (C) 2018 Pavlo Solntsev <p sun fun gmail com> 
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -3331,12 +3332,15 @@ gda_parse_formatted_time (GdaTime *timegda, const gchar *value, gchar sep)
  *
  * Accepted date format is "YYYY-MM-DDTHH:MM:SS[.ms][TZ]" where TZ is +hour or -hour
  *
- * Returns: a new #GDateTime if @value has been sucessfuly parsed as a valid timestamp (see g_date_valid())
+ * Returns: a new #GDateTime if @value has been successfully parsed as a valid timestamp (see 
g_date_valid()). The returned instance should be freed using g_date_time_unref().
  */
 GDateTime*
 gda_parse_iso8601_timestamp (const gchar *value)
 {
-       return gda_parse_formatted_timestamp (value, G_DATE_YEAR, G_DATE_MONTH, G_DATE_DAY, '-');
+  GTimeZone *tz = g_time_zone_new_utc ();
+  GDateTime *dt = g_date_time_new_from_iso8601 (value,tz);
+  g_time_zone_unref (tz);
+  return dt;
 }
 
 /**
@@ -3345,12 +3349,12 @@ gda_parse_iso8601_timestamp (const gchar *value)
  * @first: a #GDateDMY specifying which of year, month or day appears first (in the first bytes) in @value
  * @second: a #GDateDMY specifying which of year, month or day appears second (in the first bytes) in @value
  * @third: a #GDateDMY specifying which of year, month or day appears third (in the first bytes) in @value
- * @sep: spcifies the expected separator character bewteen year, month and day (for example '-')
+ * @sep: specifies the expected separator character between year, month and day (for example '-')
  *
  * This function is similar to gda_parse_iso8601_timestamp() (with @first being @G_DATE_YEAR, @second being 
@G_DATE_MONTH,
  * @third being @G_DATE_DAY and @sep being '-') but allows one to specify the expected date format.
  *
- * Returns: (nullable): a new #GDateTime if @value has been sucessfuly parsed as a valid date (see 
g_date_valid()).
+ * Returns: (nullable): a new #GDateTime if @value has been successfully parsed as a valid date (see 
g_date_valid()).
  * 
  * Since: 5.2
  */
diff --git a/libgda/gda-util.h b/libgda/gda-util.h
index 721239690..417622d5d 100644
--- a/libgda/gda-util.h
+++ b/libgda/gda-util.h
@@ -119,6 +119,8 @@ void         gda_connection_string_split (const gchar *string, gchar **out_cnc_p
  */
 gboolean     gda_parse_iso8601_date (GDate *gdate, const gchar *value);
 gboolean     gda_parse_iso8601_time (GdaTime *timegda, const gchar *value);
+
+GLIB_DEPRECATED_FOR(g_date_time_new_from_iso8601)
 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);
diff --git a/libgda/gda-value.c b/libgda/gda-value.c
index 0a0a18cd9..01596ebe1 100644
--- a/libgda/gda-value.c
+++ b/libgda/gda-value.c
@@ -218,12 +218,14 @@ set_from_string (GValue *value, const gchar *as_string)
                gda_time_free (timegda);
        }
        else if (g_type_is_a (type, G_TYPE_DATE_TIME)) {
-               GDateTime* timestamp = gda_parse_iso8601_timestamp (as_string);
+    GTimeZone *tz = g_time_zone_new_utc ();
+    GDateTime* timestamp = g_date_time_new_from_iso8601 (as_string,tz);
                if (timestamp) {
                        g_value_set_boxed (value, timestamp);
                        retval = TRUE;
+                 g_date_time_unref (timestamp);
                }
-               g_date_time_unref (timestamp);
+               g_time_zone_unref (tz);
        }
        else if (type == GDA_TYPE_NULL) {
                gda_value_set_null (value);
@@ -1946,87 +1948,35 @@ compute_tz_offset (struct tm *gmttm, struct tm *loctm)
 }
 
 /**
- * gda_value_new_timestamp_from_timet:
+ * gda_value_new_date_time_from_timet:
  * @val: value to set for the new #GValue.
  *
- * Makes a new #GValue of type #GDA_TYPE_TIMESTAMP with value @val
+ * Makes a new #GValue of type #G_TYPE_DATE_TIME with value @val
  * (of type time_t). The returned timestamp's value is relative to the current
  * timezone (i.e. is localtime).
  *
  * For example, to get a time stamp representing the current date and time, use:
  *
  * <code>
- * ts = gda_value_new_timestamp_from_timet (time (NULL));
+ * ts = gda_value_new_date_time_from_timet (time (NULL));
  * </code>
  *
  * Returns: (transfer full): the newly created #GValue, or %NULL in case of error
  *
  * Free-function: gda_value_free
+ *
+ * Deprecated: 6.0: Use gda_value_new_date_time_from_timet() instead
  */
 GValue *
-gda_value_new_timestamp_from_timet (time_t val)
+gda_value_new_date_time_from_timet (time_t val)
 {
-       GValue *value = NULL;
-       struct tm *ltm = NULL;
-       glong tz = 0;
-
-#ifdef HAVE_LOCALTIME_R
-       struct tm gmttm, loctm;
-       tzset ();
-       ltm = localtime_r ((const time_t *) &val, &loctm);
-       tz = compute_tz_offset (gmtime_r ((const time_t *) &val, &gmttm), &loctm);
-       if (tz == G_MAXLONG)
-               ltm = NULL;
-#elif HAVE_LOCALTIME_S
-       struct tm gmttm, loctm;
-       if ((localtime_s (&loctm, (const time_t *) &val) == 0) &&
-           (gmtime_s (&gmttm, (const time_t *) &val) == 0)) {
-               tz = compute_tz_offset (&gmttm, &loctm);
-               if (tz != G_MAXLONG)
-                       ltm = &loctm;
-       }
-#else
-       struct tm gmttm, loctm;
-       ltm = gmtime ((const time_t *) &val);
-       if (ltm) {
-               gmttm = *ltm;
-               ltm = localtime ((const time_t *) &val);
-               if (ltm) {
-                       loctm = *ltm;
-                       tz = compute_tz_offset (&gmttm, &loctm);
-                       if (tz == G_MAXLONG)
-                               ltm = NULL;
-               }
-       }
-       
-#endif
+  GValue *value;
+  GDateTime* tstamp = g_date_time_new_from_unix_utc ((gint64)val);
 
-       if (ltm) {
-               gint tzi = tz;
-               if (tzi < 0)
-                       tzi *= -1;
-               gint h = tzi/60/60;
-               gint m = tzi/60 - h*60;
-               gint s = tzi - h*60*60 - m*60;
-               gchar *stz = g_strdup_printf ("%s%02d:%02d:%02d",
-                                                                                                             
                          tz < 0 ? "-" : "+",
-                                                                                                             
                          h, m, s);
-               GTimeZone *tzo = g_time_zone_new (stz);
-               g_free (stz);
-               GDateTime* tstamp = g_date_time_new (tzo,
-                                                                                                             
                  ltm->tm_year + 1900,
-                                                                                                             
                  ltm->tm_mon + 1,
-                                                                                                             
                  ltm->tm_mday,
-                                                                                                             
                  ltm->tm_hour,
-                                                                                                             
                  ltm->tm_min,
-                                                                                                             
                  ltm->tm_sec);
-
-               g_time_zone_unref (tzo);
-               value = g_new0 (GValue, 1);
-               g_value_init (value, G_TYPE_DATE_TIME);
-               g_value_set_boxed (value, tstamp);
-               g_date_time_unref (tstamp);
-       }
+  value = g_new0 (GValue, 1);
+  g_value_init (value, G_TYPE_DATE_TIME);
+  g_value_set_boxed (value, tstamp);
+  g_date_time_unref (tstamp);
 
        return value;
 }
diff --git a/libgda/gda-value.h b/libgda/gda-value.h
index ffb366649..a4a27d0d1 100644
--- a/libgda/gda-value.h
+++ b/libgda/gda-value.h
@@ -58,10 +58,6 @@ G_BEGIN_DECLS
 #define GDA_VALUE_HOLDS_SHORT(value)           G_VALUE_HOLDS(value, GDA_TYPE_SHORT)
 #define GDA_VALUE_HOLDS_USHORT(value)          G_VALUE_HOLDS(value, GDA_TYPE_USHORT)
 #define GDA_VALUE_HOLDS_TIME(value)            G_VALUE_HOLDS(value, GDA_TYPE_TIME)
-#define GDA_VALUE_HOLDS_TIMESTAMP(value)       G_VALUE_HOLDS(value, GDA_TYPE_TIMESTAMP)
-
-/* GLIb types */
-#define G_VALUE_HOLDS_DATETIME(value)       G_VALUE_HOLDS(value, GDA_TYPE_TIMESTAMP)
 
 
 /* GdaNumeric */
@@ -201,7 +197,7 @@ GValue                           *gda_value_new_default (const gchar *default_va
 GValue                           *gda_value_new_blob (const guchar *val, glong size);
 GValue                           *gda_value_new_blob_from_file (const gchar *filename);
 GValue                           *gda_value_new_time_from_timet (time_t val);
-GValue                           *gda_value_new_timestamp_from_timet (time_t val);
+GValue                           *gda_value_new_date_time_from_timet (time_t val);
 
 GValue                           *gda_value_new_from_string (const gchar *as_string, GType type);
 GValue                           *gda_value_new_from_xml (const xmlNodePtr node);
diff --git a/libgda/libgda.symbols b/libgda/libgda.symbols
index 7272932d2..0f53738db 100644
--- a/libgda/libgda.symbols
+++ b/libgda/libgda.symbols
@@ -876,7 +876,6 @@
        gda_timestamp_copy
        gda_timestamp_change_timezone
        gda_timestamp_free
-       gda_timestamp_get_type
        gda_timestamp_valid
        gda_transaction_isolation_get_type
        gda_transaction_status_add_event_sql
diff --git a/tests/providers/prov-test-common.c b/tests/providers/prov-test-common.c
index b2b1879bd..deadc3ca3 100644
--- a/tests/providers/prov-test-common.c
+++ b/tests/providers/prov-test-common.c
@@ -744,7 +744,7 @@ prov_test_common_check_timestamp (void)
                parser = gda_sql_parser_new ();
 
        GValue *tso;
-       tso = gda_value_new_timestamp_from_timet (time (NULL));
+       tso = gda_value_new_date_time_from_timet (time (NULL));
 
        /* insert timestamp */
        stmt = gda_sql_parser_parse_string (parser, "INSERT INTO tstest (ts) VALUES (##ts::timestamp)", NULL, 
&error);
diff --git a/tests/test-input-parsers.c b/tests/test-input-parsers.c
index cb34e0ecc..160bfad32 100644
--- a/tests/test-input-parsers.c
+++ b/tests/test-input-parsers.c
@@ -68,12 +68,12 @@ typedef struct {
 TestDate datedata[] = {
        {"1996-11-22", TRUE, 22, 11, 1996},
        {"1996-22-23", FALSE, 0, 0, 0},
-       {"96-7-23", TRUE, 23, 7, 96},
+       {"0096-07-23", TRUE, 23, 7, 96},
        {"2050-12-31", TRUE, 31, 12, 2050},
        {"2050-11-31", FALSE, 0, 0, 0},
        {"1996-02-29", TRUE, 29, 2, 1996},
        {"1997-02-29", FALSE, 0, 0, 0},
-       {"1900-5-22", TRUE, 22, 5, 1900},
+       {"1900-05-22", TRUE, 22, 5, 1900},
        {"1900.05-22", FALSE, 0, 0, 0},
        {"1900-05.22", FALSE, 0, 0, 0},
        {"1900-05-22 ", FALSE, 0, 0, 0},
@@ -83,7 +83,7 @@ TestDate datedata[] = {
        {"1900-05 -22", FALSE, 0, 0, 0},
        {"1900-05- 22", FALSE, 0, 0, 0},
        {"65535-05-22", TRUE, 22, 5, 65535},
-       {"1-05-22", TRUE, 22, 5, 1},
+       {"0001-05-22", TRUE, 22, 5, 1},
        {"65536-05-22", FALSE, 0, 0, 0},
 };
 
@@ -131,27 +131,25 @@ typedef struct {
 
 TestTime timedata[] = {
        {"11:22:56Z",TRUE, 11, 22, 56, 0, 0},
-       {"1:22:56Z",TRUE, 1, 22, 56, 0, 0},
+       {"01:22:56Z",TRUE, 1, 22, 56, 0, 0},
        {"1:22:60Z",FALSE, 1, 22, 0, 0, 0},
        {"1:60:45Z",FALSE, 1, 0, 0, 0, 0},
        {"24:23:45Z",FALSE, 0, 0, 0, 0, 0},
        {"23:59:59Z",TRUE, 23, 59, 59, 0, 0},
-       {"0:0:00Z",TRUE, 0, 0, 0, 0, 0},
-       {"12:1:0Z",TRUE, 12, 1, 0, 0, 0},
+       {"00:00:00Z",TRUE, 0, 0, 0, 0, 0},
+       {"12:01:00Z",TRUE, 12, 1, 0, 0, 0},
        {" 12:00:00Z",FALSE, 0, 0, 0, 0, 0},
        {"12 :00:00Z",FALSE, 12, 0, 0, 0, 0},
        {"12: 00:00Z",FALSE, 12, 0, 0, 0, 0},
        {"12: 00:00Z",FALSE, 12, 0, 0, 0, 0},
        {"12:1 :00Z",FALSE, 12, 1, 0, 0, 0},
-       {"12:1:2 Z",TRUE, 12, 1, 2, 0, 0},
-       {"12:1:2.Z",TRUE, 12, 1, 2, 0, 0},
-       {"12:1:2:Z",TRUE, 12, 1, 2, 0, 0},
-       {"12:1:2.123Z",TRUE, 12, 1, 2, 123000, 0},
-       {"12:1:2-2",TRUE, 12, 1, 2, 0, -2l*60*60},
-       {"12:1:2+11",TRUE, 12, 1, 2, 0, 11l*60*60},
-       {"12:1:2.1234+11",TRUE, 12, 1, 2, 123400, 11l*60*60},
-       {"12:1:2.123456-3",TRUE, 12, 1, 2, 123456, -3l*60*60},
-       {"12:1:2.123456 UTC", TRUE, 12, 1, 2, 123456, 0},
+       {"12:01:02Z",TRUE, 12, 1, 2, 0, 0},
+       {"12:01:02.123Z",TRUE, 12, 1, 2, 123000, 0},
+       {"12:01:02-02",TRUE, 12, 1, 2, 0, -2l*60*60},
+       {"12:01:02+11",TRUE, 12, 1, 2, 0, 11l*60*60},
+       {"12:01:02.1234+11",TRUE, 12, 1, 2, 123400, 11l*60*60},
+       {"12:01:02.123456-03",TRUE, 12, 1, 2, 123456, -3l*60*60},
+       {"12:01:02.123456Z", TRUE, 12, 1, 2, 123456, 0},
 };
 
 static gboolean


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