]> git.mxchange.org Git - simgear.git/blobdiff - simgear/timing/sg_time.cxx
Added a touch of error checking to the screen dump routine, i.e. don't
[simgear.git] / simgear / timing / sg_time.cxx
index 3aa89d92e4d30c1d54cdeadb01912f61dce0b1a9..e10400c3afe2fe5358e8bc7c1be4e61bf16f9c40 100644 (file)
@@ -75,18 +75,24 @@ SGTime::SGTime( double lon, double lat, const string& root )
     // cout << "Current local time          = " 
     //      << asctime(localtime(&cur_time)) << endl;
 
-    FGPath zone( root );
-    zone.append( "zone.tab" );
-    FG_LOG( FG_EVENT, FG_DEBUG, "Reading timezone info from: " << zone.str() );
-    tzContainer = new TimezoneContainer( zone.c_str() );
-
-    GeoCoord location( RAD_TO_DEG * lat, RAD_TO_DEG * lon );
-    GeoCoord* nearestTz = tzContainer->getNearest(location);
-
-    FGPath name( root );
-    name.append( nearestTz->getDescription() );
-    zonename = strdup( name.c_str() );
-    // cout << "Using zonename = " << zonename << endl;
+    if ( root != "" ) {
+       FGPath zone( root );
+       zone.append( "zone.tab" );
+       FG_LOG( FG_EVENT, FG_DEBUG, "Reading timezone info from: "
+               << zone.str() );
+       tzContainer = new TimezoneContainer( zone.c_str() );
+
+       GeoCoord location( RAD_TO_DEG * lat, RAD_TO_DEG * lon );
+       GeoCoord* nearestTz = tzContainer->getNearest(location);
+
+       FGPath name( root );
+       name.append( nearestTz->getDescription() );
+       zonename = strdup( name.c_str() );
+       // cout << "Using zonename = " << zonename << endl;
+    } else {
+       tzContainer = NULL;
+       zonename = NULL;
+    }
 }
 
 
@@ -95,9 +101,16 @@ SGTime::SGTime( const string& root ) {
 }
 
 
+SGTime::SGTime() {
+    SGTime( 0.0, 0.0, "" );
+}
+
+
 SGTime::~SGTime()
 {
-    delete tzContainer;
+    if ( tzContainer != NULL ) {
+       delete tzContainer;
+    }
 
     if ( zonename != NULL ) {
        delete zonename;