[gnome-clocks] Timer: Show correct time



commit 690ebedbfbb7b39a3c433e6a34623d165d2a7ff7
Author: Volker Sobek <reklov live com>
Date:   Thu Nov 29 04:30:41 2012 +0100

    Timer: Show correct time
    
    Take into account that the timer runs backwards. The timer didn't show
    the correct time, e.g. it displayed 0 seconds when actually one second
    was left.

 gnomeclocks/timer.py |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/gnomeclocks/timer.py b/gnomeclocks/timer.py
index c60abd7..b873681 100644
--- a/gnomeclocks/timer.py
+++ b/gnomeclocks/timer.py
@@ -17,6 +17,7 @@
 # Author: Seif Lotfy <seif lotfy collabora co uk>
 
 import time
+import math
 from gi.repository import GLib,  GObject, Gtk
 from clocks import Clock
 from utils import Alert
@@ -232,8 +233,11 @@ class Timer(Clock):
             self.show_setup_screen(False)
             return False
         elif not self._ui_is_frozen:
-            r = self.deadline - t
-            m, s = divmod(r, 60)
+            # math.ceil() is needed because we count backwards. It assures the
+            # display shows the past and not the future, e.g. show 1 s and not
+            # 0 s when we are at 0.3 s.
+            display_time = math.ceil(self.deadline - t)
+            m, s = divmod(display_time, 60)
             h, m = divmod(m, 60)
             self.timer_screen.set_time(h, m, s)
         return True



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]