helpers.py
changeset 60 759369a79527
parent 58 ce028d356e1f
child 62 e7ca94b94a4e
--- a/helpers.py	Mon Feb 09 06:56:04 2009 +0200
+++ b/helpers.py	Mon Feb 09 07:06:49 2009 +0200
@@ -2,9 +2,11 @@
     Some additional helpers
 """
 
+import datetime, calendar
+
 import qmsk.web.helpers
 
-import datetime, calendar
+import preferences
 
 class Helpers (qmsk.web.helpers.Helpers) :
     """
@@ -18,14 +20,6 @@
 
         return str(tz)
 
-    def fmt_date (self, date) :
-        """
-            Formats a date
-        """
-        
-        # XXX: hardcoded
-        return date.strftime('%Y-%m-%d')
-
     def fmt_month (self, date) :
         """
             Formats a month
@@ -121,4 +115,26 @@
 
         else :
             return month.month + 1
+    
+    def fmt_time (self, time=None) :
+        """
+            Format given time, or current time
+        """
+        
+        # defaults
+        if not time :
+            time = self.now()
 
+        return time.strftime(self.ctx['prefs'][preferences.time_format])
+
+    def fmt_date (self, date=None) :
+        """
+            Format given date, or current date
+        """
+        
+        # defaults
+        if not date :
+            date = self.now()
+
+        return date.strftime(self.ctx['prefs'][preferences.date_format])
+