[gnome-clocks] Fix remaining holes in snooze



commit 7553f31af238b03acb7b1cfcd5f5ef6717eb2c7d
Author: Volker Sobek <reklov live com>
Date:   Fri Nov 16 12:40:34 2012 +0100

    Fix remaining holes in snooze
    
    This fixes three cases that commit 79875341 didn't cover:
    
    1) If the user didn't click Stop after an alarm rang, the snooze time
       kept referring to this alarm time, even after the next alarm time
       was reached. (This broke snooze after the next alarm time.)
    
    2) If the alarm was snoozing when the next alarm time was reached,
       snooze was not turned off. [0]
    
    3) When checking for expiration times, the snooze time was checked
       before the alarm time. In case they were both identical [0] this
       updated only the snooze time, incorrectly referring to the last
       snooze time.
    
    TL;DR: Completely reset snooze once a new alarm time has been reached.
    
    [0] Very unlikely to ever hit this case with the current snooze time,
    but theoretically possible.

 gnomeclocks/alarm.py |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
---
diff --git a/gnomeclocks/alarm.py b/gnomeclocks/alarm.py
index 332aa08..b1d060c 100644
--- a/gnomeclocks/alarm.py
+++ b/gnomeclocks/alarm.py
@@ -89,7 +89,7 @@ class AlarmItem:
 
         if not hour == None and not minute == None:
             self._update_expiration_time()
-            self._update_snooze_expiration_time(self.time)
+            self._reset_snooze(self.time)
 
     def _update_expiration_time(self):
         now = datetime.now()
@@ -105,15 +105,15 @@ class AlarmItem:
                 dt += timedelta(weeks=1, days=(self.days[0] - dt.weekday()))
         self.time = dt
 
-    def _update_snooze_expiration_time(self, start_time):
+    def _reset_snooze(self, start_time):
         self.snooze_time = start_time + timedelta(minutes=9)
+        self.is_snoozing = False
 
     def snooze(self):
         self.is_snoozing = True
 
     def stop(self):
-        self.is_snoozing = False
-        self._update_snooze_expiration_time(self.time)
+        self._reset_snooze(self.time)
 
     def get_time_as_string(self):
         if SystemSettings.get_clock_format() == "12h":
@@ -141,13 +141,13 @@ class AlarmItem:
 
     def check_expired(self):
         t = datetime.now()
-        if self.is_snoozing and t > self.snooze_time:
-            self._update_snooze_expiration_time(self.snooze_time)
-            self.is_snoozing = False
-            return True
-        elif t > self.time:
+        if t > self.time:
+            self._reset_snooze(self.time)
             self._update_expiration_time()
             return True
+        elif self.is_snoozing and t > self.snooze_time:
+            self._reset_snooze(self.snooze_time)
+            return True
         else:
             return False
 



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