server/sqlutils.py
branchstable
changeset 7904 f41bb38dda7c
parent 7341 c419c2d0d13e
child 7907 08320697ca1a
--- a/server/sqlutils.py	Tue Oct 04 10:15:46 2011 +0200
+++ b/server/sqlutils.py	Tue Oct 04 10:18:35 2011 +0200
@@ -338,6 +338,17 @@
         return _limit_size(text, maxsize)
     cnx.create_function("TEXT_LIMIT_SIZE", 2, limit_size2)
 
+    from logilab.common.date import strptime
+    def weekday(ustr):
+        try:
+            dt = strptime(ustr, '%Y-%m-%d %H:%M:%S')
+        except:
+            dt =  strptime(ustr, '%Y-%m-%d')
+        # expect sunday to be 1, saturday 7 while weekday method return 0 for
+        # monday
+        return (dt.weekday() + 1) % 7
+    cnx.create_function("WEEKDAY", 1, weekday)
+
     import yams.constraints
     yams.constraints.patch_sqlite_decimal()