[gnome-clocks] AlarmDialog: Fix time when editing alarm in 12h format



commit e598f8cc1d7caa1100f176f67d4104ff47fe6494
Author: Volker Sobek <reklov live com>
Date:   Wed Nov 21 14:12:53 2012 +0100

    AlarmDialog: Fix time when editing alarm in 12h format
    
    When editing an existing alarm using the 12h format, the number for
    the hour SpinButton was not calculated correctly. For example, when
    you edited a 6:10 PM alarm, the edit dialog would open it as 1:10 PM.

 gnomeclocks/alarm.py |   18 +++++++-----------
 1 files changed, 7 insertions(+), 11 deletions(-)
---
diff --git a/gnomeclocks/alarm.py b/gnomeclocks/alarm.py
index cb9f956..ac839aa 100644
--- a/gnomeclocks/alarm.py
+++ b/gnomeclocks/alarm.py
@@ -183,12 +183,7 @@ class AlarmDialog(Gtk.Dialog):
         content_area.pack_start(grid, True, True, 0)
 
         if alarm:
-            if self.cf == "12h":
-                h = int(alarm.time.strftime("%I"))
-                p = alarm.time.strftime("%p")
-            else:
-                h = alarm.hour
-                p = None
+            h = alarm.hour
             m = alarm.minute
             name = alarm.name
             days = alarm.days
@@ -196,7 +191,6 @@ class AlarmDialog(Gtk.Dialog):
             t = time.localtime()
             h = t.tm_hour
             m = t.tm_min
-            p = time.strftime("%p", t)
             name = _("New Alarm")
             days = []
 
@@ -229,11 +223,13 @@ class AlarmDialog(Gtk.Dialog):
             self.ampm = Gtk.ComboBoxText()
             self.ampm.append_text("AM")
             self.ampm.append_text("PM")
-            if p == "PM":
-                h = h - 12
-                self.ampm.set_active(1)
+            if h < 12:
+                self.ampm.set_active(0)  # AM
             else:
-                self.ampm.set_active(0)
+                self.ampm.set_active(1)  # PM
+                h -= 12
+            if h == 0:
+                h = 12
             grid.attach(self.ampm, 4, 0, 1, 1)
             self.hourselect.set_range(1.0, 12.0)
             self.hourselect.set_value(h)



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