Fix:Core:Avoid gmtime_r which isn't available on all platforms
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Fri, 13 Nov 2009 07:59:59 +0000 (07:59 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Fri, 13 Nov 2009 07:59:59 +0000 (07:59 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@2751 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/navit.c
navit/navit/sunriset.h

index bf74984..5e9ab6e 100644 (file)
@@ -2265,6 +2265,7 @@ navit_layout_switch(struct navit *n)
     struct attr iso8601_attr,geo_attr,layout_attr;
     double trise,tset,trise_actual;
     struct layout *l;
+    int year, month, day;
     
     if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
        return; //No layout - nothing to switch
@@ -2282,7 +2283,8 @@ navit_layout_switch(struct navit *n)
            //We've have to wait a little
            return;
        }
-       
+       if (sscanf(iso8601_attr.u.str,"%d-%02d-%02dT",&year,&month,&day) != 3)
+               return;
        if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo,&geo_attr,NULL)!=1) {
                //No position - no sun
                return;
@@ -2292,7 +2294,7 @@ navit_layout_switch(struct navit *n)
        }
        
        //We calculate sunrise anyway, cause it is need both for day and for night
-        if (__sunriset__(currTs,geo_attr.u.coord_geo->lat,geo_attr.u.coord_geo->lng,35,1,&trise,&tset)!=0) {
+        if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lat,geo_attr.u.coord_geo->lng,35,1,&trise,&tset)!=0) {
                //near the pole sun never rises/sets, so we should never switch profiles
                n->prevTs=currTs;
                return;
@@ -2311,7 +2313,7 @@ navit_layout_switch(struct navit *n)
            }
        }
        if (l->nightname) {
-           if (__sunriset__(currTs,geo_attr.u.coord_geo->lat,geo_attr.u.coord_geo->lng,-12,0,&trise,&tset)!=0) {
+           if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lat,geo_attr.u.coord_geo->lng,-12,0,&trise,&tset)!=0) {
                //near the pole sun never rises/sets, so we should never switch profiles
                n->prevTs=currTs;
                return;
index 1ccad57..9df6ca2 100644 (file)
@@ -7,7 +7,7 @@ extern long int timezone_offset;
 #define HOURS(h) ((int)(floor(h)))
 #define MINUTES(h) ((int)(60*(h-floor(h))))
 
-#define ABS(x) ((x)<0?-(x):(x))
+#define ABS(x) ((x)<0?-(x):(x)) 
 
 /* A macro to compute the number of days elapsed since 2000 Jan 0.0 */
 /* (which is equal to 1999 Dec 31, 0h UT)                           */
@@ -100,7 +100,7 @@ extern long int timezone_offset;
 double __daylen__( int year, int month, int day, double lon, double lat,
                    double altit, int upper_limb );
 
-int __sunriset__( time_t ts, double lon, double lat,
+int __sunriset__( int year, int month, int day, double lon, double lat,
                   double altit, int upper_limb, double *rise, double *set );
 
 void sunpos( double d, double *lon, double *r );