Add countdown functionality with same modes as the
[stopish] / src / timer.c
index a17e21f..fe42c75 100644 (file)
@@ -60,13 +60,26 @@ char *stopish_get_time_string( void )
         h = m = s = ss = 0;
     }
 
+    if ( stopish_get_type(  ) == STOPISH_TYPE_COUNTDOWN ) {
+        h = -h;
+        m = -m;
+        s = -s;
+        ss = -ss;
+    }
+    // countdown check
+    if ( stopish_get_type(  ) == STOPISH_TYPE_COUNTDOWN &&
+         ( h == 0 && m == 0 && s == 0 && ss == 0 ) )
+        return NULL;
+
     timeBuffer = malloc( 64 );
     if ( timerPrecision == TIMER_PRECISION_MINUTE )
         sprintf( timeBuffer, "%.02d:%.02d.%.1d",
-                 m, s, ss );
+                 ( unsigned int ) m, ( unsigned int ) s,
+                 ( unsigned int ) ss );
     else
         sprintf( timeBuffer, "%.02d:%.02d:%.02d.%.1d",
-                 h, m, s, ss );
+                 ( unsigned int ) h, ( unsigned int ) m,
+                 ( unsigned int ) s, ( unsigned int ) ss );
 
     return timeBuffer;
 }