From 1e350545224b9daaba4db2c0df8cd8be0d604af7 Mon Sep 17 00:00:00 2001 From: martin-s Date: Tue, 10 Mar 2009 16:31:08 +0000 Subject: [PATCH] Fix:Core:Avoid strptime (not available on win32/wince) git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@2094 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/navit.c | 7 +++---- navit/navit/util.c | 28 ++++++++++++++++++++++++++++ navit/navit/util.h | 1 + 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/navit/navit/navit.c b/navit/navit/navit.c index 2fed1a0..a46087f 100644 --- a/navit/navit/navit.c +++ b/navit/navit/navit.c @@ -59,6 +59,7 @@ #include "profile.h" #include "command.h" #include "navit_nls.h" +#include "util.h" /** * @defgroup navit the navit core instance. navit is the object containing nearly everything: A set of maps, one or more vehicle, a graphics object for rendering the map, a gui object for displaying the user interface, a route object, a navigation object and so on. Be warned that it is theoretically possible to have more than one navit object @@ -1872,7 +1873,6 @@ navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv) enum projection pro; int border=16; time_t fixtime; - struct tm fixtime_tm; int recenter = 1; // indicates if we should recenter the map profile(0,NULL); @@ -1917,14 +1917,13 @@ navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv) cursor_pc.pro = pro; if (this_->tracking && this_->tracking_flag) { if (! vehicle_get_attr(nv->vehicle, attr_position_hdop, &attr_hdop, NULL)) { - attr_hdop.u.numd = -1; + attr_hdop.u.numd = NULL; } if (! vehicle_get_attr(nv->vehicle, attr_position_time_iso8601, &attr_time, NULL)) { fixtime = time(NULL); } else { - strptime(attr_time.u.str, "%Y-%m-%dT%TZ", &fixtime_tm); - fixtime = mktime(&fixtime_tm); + fixtime = iso8601_to_secs(attr_time.u.str); } if (tracking_update(this_->tracking, &cursor_pc, nv->dir, attr_hdop.u.numd, nv->speed, fixtime)) { diff --git a/navit/navit/util.c b/navit/navit/util.c index 9fb374f..6a8e710 100644 --- a/navit/navit/util.c +++ b/navit/navit/util.c @@ -19,6 +19,7 @@ #include #include +#include #include #include "util.h" @@ -253,3 +254,30 @@ char * newSysString(const char *toconvert) } #endif #endif + +unsigned int +iso8601_to_secs(char *iso8601) +{ + int a,b,d,val[6],i=0; + char *start=iso8601,*pos=iso8601; + while (*pos && i < 6) { + if (*pos < '0' || *pos > '9') { + val[i++]=atoi(start); + pos++; + start=pos; + } + pos++; + } + + a=val[0]/100; + b=2-a+a/4; + + if (val[1] < 2) { + val[0]--; + val[1]+=12; + } + + d=1461*(val[0]+4716)/4+306001*(val[1]+1)/10000+val[2]+b-2442112; + + return ((d*24+val[3])*60+val[4])*60+val[5]; +} diff --git a/navit/navit/util.h b/navit/navit/util.h index 737b5a4..4195101 100644 --- a/navit/navit/util.h +++ b/navit/navit/util.h @@ -27,6 +27,7 @@ void strtolower(char *dest, const char *src); GList * g_hash_to_list(GHashTable *h); GList * g_hash_to_list_keys(GHashTable *h); gchar * g_strconcat_printf(gchar *buffer, gchar *fmt, ...); +unsigned int iso8601_to_secs(char *iso8601); #endif -- 2.7.4