From 8b27ce4512628c1439128689eb01f0e4bc201856 Mon Sep 17 00:00:00 2001 From: martin-s Date: Sun, 12 Jul 2009 16:13:41 +0000 Subject: Fix:vehicle_demo:Give back a reasonable timestamp git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit/navit@2394 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- util.c | 22 ++++++++++++++++++++++ util.h | 2 +- vehicle.c | 23 +++++------------------ vehicle/demo/vehicle_demo.c | 6 ++++++ 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/util.c b/util.c index e2d8a7d9..73742ae1 100644 --- a/util.c +++ b/util.c @@ -284,3 +284,25 @@ iso8601_to_secs(char *iso8601) return ((d*24+val[3])*60+val[4])*60+val[5]; } + +char * +current_to_iso8601(void) +{ + char buffer[32]; + char *timep=NULL; +#ifdef HAVE_GLIB + GTimeVal time; + g_get_current_time(&time); + timep = g_time_val_to_iso8601(&time); +#else + time_t tnow; + struct tm *tm; + tnow = time(0); + tm = gmtime(&tnow); + if (tm) { + strftime(buffer, sizeof(buffer), "%Y-%m-%dT%TZ", tm); + timep=g_strdup(buffer); + } +#endif + return timep; +} diff --git a/util.h b/util.h index 3dd9447b..b578e282 100644 --- a/util.h +++ b/util.h @@ -35,6 +35,6 @@ char * newSysString(const char *toconvert); #endif #endif unsigned int iso8601_to_secs(char *iso8601); - +char * current_to_iso8601(void); #endif diff --git a/vehicle.c b/vehicle.c index cf63a3c4..81b8903b 100644 --- a/vehicle.c +++ b/vehicle.c @@ -57,36 +57,23 @@ vehicle_log_gpx(struct vehicle *this_, struct log *log) char buffer[256]; char tbuf[256]; char *timep; + int free=0; if (!this_->meth.position_attr_get) return; if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &pos_attr)) return; if (!this_->meth.position_attr_get(this_->priv, attr_position_time_iso8601, &time_attr)) { -#ifdef HAVE_GLIB - GTimeVal time; - g_get_current_time(&time); - timep = g_time_val_to_iso8601(&time); - sprintf(tbuf, "%s", timep); - g_free(timep); - timep = tbuf; -#else - time_t tnow; - struct tm *tm; - tnow = time(0); - tm = gmtime(&tnow); - if (tm) { - strftime(tbuf, sizeof(tbuf), - "%Y-%m-%dT%TZ", tm); - } - timep = tbuf; -#endif + timep = current_to_iso8601(); + free=1; } else { timep = time_attr.u.str; } sprintf(buffer,"\n\t\n\n", pos_attr.u.coord_geo->lat, pos_attr.u.coord_geo->lng, timep); log_write(log, buffer, strlen(buffer)); + if (free) + g_free(timep); } static void diff --git a/vehicle/demo/vehicle_demo.c b/vehicle/demo/vehicle_demo.c index 76d56349..f1316fc0 100644 --- a/vehicle/demo/vehicle_demo.c +++ b/vehicle/demo/vehicle_demo.c @@ -44,6 +44,7 @@ struct vehicle_priv { double direction; struct callback *timer_callback; struct event_timeout *timer; + char *timep; }; @@ -67,6 +68,11 @@ vehicle_demo_position_attr_get(struct vehicle_priv *priv, case attr_position_coord_geo: attr->u.coord_geo = &priv->geo; break; + case attr_position_time_iso8601: + g_free(priv->timep); + priv->timep=current_to_iso8601(); + attr->u.str=priv->timep; + break; default: return 0; } -- cgit v1.2.1