diff options
-rw-r--r-- | navit/navit.c | 7 | ||||
-rw-r--r-- | navit/util.c | 28 | ||||
-rw-r--r-- | navit/util.h | 1 |
3 files changed, 32 insertions, 4 deletions
diff --git a/navit/navit.c b/navit/navit.c index 2fed1a01c..a46087f28 100644 --- a/navit/navit.c +++ b/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/util.c b/navit/util.c index 9fb374f2b..6a8e71040 100644 --- a/navit/util.c +++ b/navit/util.c @@ -19,6 +19,7 @@ #include <glib.h> #include <ctype.h> +#include <stdlib.h> #include <stdarg.h> #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/util.h b/navit/util.h index 737b5a4d1..419510184 100644 --- a/navit/util.h +++ b/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 |