[libgda: 1/2] Experimental: Porting GTimeVal to GDateTime
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda: 1/2] Experimental: Porting GTimeVal to GDateTime
- Date: Tue, 10 Mar 2020 19:43:56 +0000 (UTC)
commit 9c9d2f219b7d210be91e8f97996a9ba1b6c73dfa
Author: Pavlo Solntsev <p sun fun gmail com>
Date: Mon Mar 2 22:09:15 2020 -0600
Experimental: Porting GTimeVal to GDateTime
GDateVal is obsolete. The code adjusted to reflect this.
libgda-ui/data-entries/gdaui-entry-common-time.c | 37 +++++++-----
providers/ldap/gda-ldap-util.c | 76 ++++++------------------
tools/common/t-context.c | 8 ++-
tools/common/t-context.h | 2 +-
tools/common/web-server.c | 10 ++--
5 files changed, 53 insertions(+), 80 deletions(-)
---
diff --git a/libgda-ui/data-entries/gdaui-entry-common-time.c
b/libgda-ui/data-entries/gdaui-entry-common-time.c
index c92bc9091..30cfb4d41 100644
--- a/libgda-ui/data-entries/gdaui-entry-common-time.c
+++ b/libgda-ui/data-entries/gdaui-entry-common-time.c
@@ -504,13 +504,15 @@ real_set_value (GdauiEntryWrapper *mgwrap, const GValue *value)
GdaTime* copy;
GTimeZone *tz;
- gtim = gda_value_get_time (value);
+ gtim = gda_value_get_time (value);
priv->value_tz = gda_time_get_timezone (gtim);
priv->value_fraction = gda_time_get_fraction (gtim);
- tz = g_time_zone_new_offset (priv->displayed_tz);
+ tz = g_time_zone_new_offset (priv->displayed_tz);
- copy = gda_time_to_timezone (gtim, tz);
+ GdaTime *gtime_copy = gda_time_copy (gtim);
+ copy = gda_time_to_timezone (gtime_copy, tz);
+ gda_time_free (gtime_copy);
GValue *copy_value;
copy_value = g_new0 (GValue, 1);
@@ -604,17 +606,24 @@ real_get_value (GdauiEntryWrapper *mgwrap)
g_free (str2);
}
- if (value && (G_VALUE_TYPE (value) != GDA_TYPE_NULL)) {
- const GdaTime *gdatime;
- GTimeZone *tz;
- gdatime = gda_value_get_time (value);
- tz = g_time_zone_new_offset (priv->displayed_tz);
- GdaTime *time_copy = gda_time_to_timezone (gdatime, priv->displayed_tz);
- GdaTime *tnz = gda_time_to_timezone (time_copy, priv->value_tz);
- gda_value_set_time (value, tnz);
- gda_time_free (time_copy);
- gda_time_free (tnz);
- }
+ if (value && (G_VALUE_TYPE (value) != GDA_TYPE_NULL)) {
+ const GdaTime *gdatime;
+ GTimeZone *tz;
+ gdatime = gda_value_get_time (value);
+ tz = g_time_zone_new_offset (priv->displayed_tz);
+
+ GdaTime *gdatime_copy = gda_time_copy (gdatime);
+ GdaTime *time_copy = gda_time_to_timezone (gdatime_copy, tz);
+ gda_time_free (gdatime_copy);
+ g_time_zone_unref (tz);
+
+ tz = g_time_zone_new_offset (priv->value_tz);
+ GdaTime *tnz = gda_time_to_timezone (time_copy, tz);
+ g_time_zone_unref (tz);
+ gda_value_set_time (value, tnz);
+ gda_time_free (time_copy);
+ gda_time_free (tnz);
+ }
}
else if (type == G_TYPE_DATE_TIME) {
gchar *tmpstr;
diff --git a/providers/ldap/gda-ldap-util.c b/providers/ldap/gda-ldap-util.c
index ccd31b145..03b154225 100644
--- a/providers/ldap/gda-ldap-util.c
+++ b/providers/ldap/gda-ldap-util.c
@@ -1014,65 +1014,25 @@ gda_ldap_attr_value_to_g_value (LdapConnectionData *cdata, GType type, BerValue
/* see ftp://ftp.rfc-editor.org/in-notes/rfc4517.txt,
* section 3.3.13: Generalized Time
*/
- GTimeVal tv;
gboolean conv;
- if (! (conv = g_time_val_from_iso8601 (bv->bv_val,
- &tv))) {
- /* Add the 'T' char */
- gchar *tmp, *str;
- gint i, len;
- str = bv->bv_val;
- len = strlen (str);
- if (len > 8) {
- tmp = g_new (gchar, len + 2);
- for (i = 0; i < 8; i++)
- tmp[i] = str[i];
- tmp [8] = 'T';
- for (i = 9; str[i]; i++)
- tmp[i] = str[i-1];
- tmp[i] = 0;
- conv = g_time_val_from_iso8601 (tmp, &tv);
- g_free (tmp);
- }
- }
- if (conv) {
- struct tm *ptm;
-#ifdef HAVE_LOCALTIME_R
- struct tm tmpstm;
- ptm = localtime_r (&(tv.tv_sec), &tmpstm);
-#elif HAVE_LOCALTIME_S
- struct tm tmpstm;
- if (localtime_s (&tmpstm, &(tv.tv_sec)) == 0)
- ptm = &tmpstm;
- else
- ptm = NULL;
-#else
- ptm = localtime (&(tv.tv_sec));
-#endif
-
- if (!ptm)
- return NULL;
-
- if (g_type_is_a (type, G_TYPE_DATE_TIME)) {
- GTimeZone *tz = g_time_zone_new ("Z"); // UTC
- GDateTime *ts = g_date_time_new (tz,
-
ptm->tm_year + 1900,
-
ptm->tm_mon + 1,
-
ptm->tm_mday,
-
ptm->tm_hour,
-
ptm->tm_min,
-
ptm->tm_sec);
- value = gda_value_new (G_TYPE_DATE_TIME);
- g_value_set_boxed (value, ts);
- g_date_time_unref (ts);
- }
- else {
- GDate *date;
- date = g_date_new ();
- g_date_set_time_val (date, &tv);
- value = gda_value_new (type);
- g_value_take_boxed (value, date);
- }
+ GDateTime *dt;
+
+ dt = g_date_time_new_from_iso8601 (bv->bv_val, NULL);
+
+ if (dt) {
+ if (g_type_is_a (type, G_TYPE_DATE)) {
+ GDate *date;
+ date = g_date_new_dmy (g_date_time_get_day_of_month (dt),
+ g_date_time_get_month (dt),
+ g_date_time_get_year (dt));
+ value = gda_value_new (type);
+ g_value_take_boxed (value, date);
+ }
+
+ if (g_type_is_a (type, G_TYPE_DATE_TIME)) {
+ value = gda_value_new (G_TYPE_DATE_TIME);
+ g_value_set_boxed (value, dt);
+ }
}
}
else if (type == GDA_TYPE_BINARY) {
diff --git a/tools/common/t-context.c b/tools/common/t-context.c
index 613705145..3557d2516 100644
--- a/tools/common/t-context.c
+++ b/tools/common/t-context.c
@@ -58,7 +58,7 @@ struct _TContextPrivate {
FILE *output_stream;
gboolean output_is_pipe;
- GTimeVal last_time_used;
+ GDateTime *last_time_used;
ToolCommandGroup *command_group;
gulong sigid;
@@ -155,6 +155,8 @@ t_context_dispose (GObject *object)
console->priv = NULL;
}
+ g_date_time_unref (console->priv->last_time_used);
+
/* parent class */
parent_class->dispose (object);
}
@@ -663,9 +665,9 @@ t_context_set_connection (TContext *console, TConnection *tcnc)
*
* Returns: (transfer none): a #GTimeVal pointer
*/
-GTimeVal *
+GDateTime*
t_context_get_last_time_used (TContext *console)
{
g_return_val_if_fail (T_IS_CONTEXT (console), NULL);
- return & (console->priv->last_time_used);
+ return console->priv->last_time_used;
}
diff --git a/tools/common/t-context.h b/tools/common/t-context.h
index 901d2e880..78bab9e0f 100644
--- a/tools/common/t-context.h
+++ b/tools/common/t-context.h
@@ -69,6 +69,6 @@ FILE *t_context_get_output_stream (TContext *console, gboolean *out
void t_context_set_connection (TContext *console, TConnection *tcnc);
TConnection *t_context_get_connection (TContext *console);
-GTimeVal *t_context_get_last_time_used (TContext *console);
+GDateTime *t_context_get_last_time_used (TContext *console);
#endif
diff --git a/tools/common/web-server.c b/tools/common/web-server.c
index 044f1148b..624ac80e2 100644
--- a/tools/common/web-server.c
+++ b/tools/common/web-server.c
@@ -1818,14 +1818,13 @@ static gboolean
delete_consoles (WebServer *server)
{
GSList *list;
- GTimeVal tv;
+ GDateTime *dt = g_date_time_new_now_local();
- g_get_current_time (&tv);
for (list = server->priv->terminals_list; list; ) {
TContext *console = (TContext *) list->data;
- GTimeVal *lastused;
+ GDateTime *lastused;
lastused = t_context_get_last_time_used (console);
- if (lastused->tv_sec + 600 < tv.tv_sec) {
+ if (g_date_time_get_second (lastused) + 600 < g_date_time_get_second (dt)) {
GSList *n = list->next;
server->priv->terminals_list = g_slist_delete_link (server->priv->terminals_list,
list);
list = n;
@@ -1834,6 +1833,9 @@ delete_consoles (WebServer *server)
else
list = list->next;
}
+
+ g_date_time_unref (dt);
+
if (! server->priv->terminals_list) {
server->priv->term_timer = 0;
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]