[gnome-clocks] Use the TimeString util also for alarms



commit c9a4fb62acba401991f369b0705c321a72271887
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Dec 2 15:25:31 2012 +0100

    Use the TimeString util also for alarms

 gnomeclocks/alarm.py |   10 ++--------
 gnomeclocks/utils.py |   11 +++++++++--
 2 files changed, 11 insertions(+), 10 deletions(-)
---
diff --git a/gnomeclocks/alarm.py b/gnomeclocks/alarm.py
index f2077e2..aeeb05b 100644
--- a/gnomeclocks/alarm.py
+++ b/gnomeclocks/alarm.py
@@ -23,7 +23,7 @@ import json
 from datetime import datetime, timedelta
 from gi.repository import GLib, GObject, Gdk, GdkPixbuf, Gtk
 from clocks import Clock
-from utils import Dirs, SystemSettings, LocalizedWeekdays, Alert
+from utils import Dirs, SystemSettings, TimeString, LocalizedWeekdays, Alert
 from widgets import SelectableIconView, ContentView
 
 
@@ -79,7 +79,7 @@ class AlarmItem:
         self._update_expiration_time()
         self._reset_snooze(self.alarm_time)
 
-        self.alarm_time_string = self._get_alarm_time_string()
+        self.alarm_time_string = TimeString.format_time(self.alarm_time)
         self.alarm_repeat_string = self._get_alarm_repeat_string()
         self.is_light = self._get_is_light()
         self.alert = Alert("alarm-clock-elapsed", name)
@@ -102,12 +102,6 @@ class AlarmItem:
         self.snooze_time = start_time + timedelta(minutes=9)
         self.is_snoozing = False
 
-    def _get_alarm_time_string(self):
-        if SystemSettings.get_clock_format() == "12h":
-            return self.alarm_time.strftime("%I:%M %p")
-        else:
-            return self.alarm_time.strftime("%H:%M")
-
     def _get_alarm_repeat_string(self):
         n = len(self.days)
         if n == 0:
diff --git a/gnomeclocks/utils.py b/gnomeclocks/utils.py
index d2b8334..6512f31 100644
--- a/gnomeclocks/utils.py
+++ b/gnomeclocks/utils.py
@@ -69,9 +69,16 @@ class TimeString:
     @staticmethod
     def format_time(t):
         if SystemSettings.get_clock_format() == "12h":
-            res = time.strftime("%I:%M %p", t)
+            fmt = "%I:%M %p"
         else:
-            res = time.strftime("%H:%M", t)
+            fmt = "%H:%M"
+
+        # "datetime" has a strftime method, "time" des not
+        if hasattr(t, 'strftime'):
+            res = t.strftime(fmt)
+        else:
+            res = time.strftime(fmt, t)
+
         if res.startswith("0"):
             res = res[1:]
         return res



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