Mercurial > getan > getan
view getan/project.py @ 135:ce707fbb9666
Change coding style of if clauses
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Wed, 31 Oct 2012 14:21:44 +0100 |
parents | 9c4e8ba3c4fa |
children | 92b7582b8f44 |
line wrap: on
line source
#!/usr/bin/env python # -*- coding: utf-8 -*- # # (c) 2008, 2009, 2010 by # Sascha L. Teichmann <sascha.teichmann@intevation.de> # Ingo Weinzierl <ingo.weinzierl@intevation.de> # # This is Free Software licensed unter the terms of GPLv3 or later. # For details see LICENSE coming with the source of 'getan'. from datetime import datetime, timedelta class Project: def __init__(self, id, key, desc, total): self.id = id self.key = key self.desc = desc self.entries = [] self.total = total self.start = None self.stop = None def year(self): total = 0 now = datetime.now() for entry in self.entries: start = entry.start if start.year == now.year: total += (entry.end - start).seconds return total def month(self): total = 0 now = datetime.now() for entry in self.entries: start = entry.start if start.month == now.month and start.year == now.year: total += (entry.end - start).seconds return total def week(self): total = 0 now = datetime.now() tweek = now.strftime('%W') for entry in self.entries: start = entry.start if start.strftime('%W') == tweek and start.year == now.year: total += (entry.end - start).seconds return total def day(self): total = 0 now = datetime.now() for entry in self.entries: start = entry.start if start.month == now.month and start.year == now.year \ and start.day == now.day: total += (entry.end - start).seconds return total class Entry: def __init__(self, id, project_id, start, end, desc): self.id = id self.project_id = project_id self.start = start self.end = end self.desc = desc def duration(self): return (self.end - self.start) def __str__(self): return ("[%s | %s | %s | %s | %s]" % (self.id, self.project_id, self.start, self.end, self.desc)) # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: