Commits

nejucomo committed 362b87e

Work around the problems with python datetime.

Comments (0)

Files changed (1)

             else:
                 nodedeps.add(nodedep)
 
+        if not (due is None or isinstance(due, datetime.date)):
+            fail('In task entry %d %r, could not parse "due" field as date: %r', i, title, due)
+
         node = Task(title, due, nodedeps, desc)
         doc2dag[id(entry)] = node
 
             # This should only ever be displayed when there are input file errors:
             return 'MISSING DEADLINE: %s' % (self.title,)
         else:
-            because = '' if (rdep is self) else ' because of %s' % (rdep,)
-            return '%s: %s%s' % (fmt_datetime(due), self.title, because)
+            because = '' if (rdep is self) else ' (because of %s)' % (rdep.title,)
+            return '%s: %s%s' % (due, self.title, because)
 
     def __cmp__(self, other):
         assert isinstance(other, Task), `other`
         (mydue, _) = self.get_deadline_constraint()
         (theirdue, _) = other.get_deadline_constraint()
-        return cmp(mydue, theirdue)
+        return cmp_datetimes(mydue, theirdue)
 
     def has_dependencies(self):
         return len(self.deps) > 0
         return (due, because)
 
 
-def fmt_datetime(dt):
-    assert isinstance(dt, datetime.date), `dt`
-    return '%04d-%02d-%02d' % (dt.year, dt.month, dt.day)
+def cmp_datetimes(a, b):
+    # Ugh... even though: isinstance(datetime.datetime(0,0,0,0,0,0), datetime.date) they cannot be compared.
 
+    def coerce(dt):
+        if not isinstance(dt, datetime.datetime):
+            dt = datetime.datetime(dt.year, dt.month, dt.day, 0, 0, 0)
+        return dt
+
+    return cmp(coerce(a), coerce(b))
 
 
 if __name__ == '__main__':