comparison getan/project.py @ 23:9c4e8ba3c4fa

Added a new implementation of 'getan' based on urwid, a python console user interface library.
author Ingo Weinzierl <ingo_weinzierl@web.de>
date Sat, 28 Aug 2010 20:16:58 +0200
parents
children 780bfda9c583 ce707fbb9666
comparison
equal deleted inserted replaced
22:2dc893ca5072 23:9c4e8ba3c4fa
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # (c) 2008, 2009, 2010 by
5 # Sascha L. Teichmann <sascha.teichmann@intevation.de>
6 # Ingo Weinzierl <ingo.weinzierl@intevation.de>
7 #
8 # This is Free Software licensed unter the terms of GPLv3 or later.
9 # For details see LICENSE coming with the source of 'getan'.
10
11 from datetime import datetime, timedelta
12
13 class Project:
14
15 def __init__(self, id, key, desc, total):
16 self.id = id
17 self.key = key
18 self.desc = desc
19 self.entries = []
20 self.total = total
21 self.start = None
22 self.stop = None
23
24 def year(self):
25 total = 0
26 now = datetime.now()
27 for entry in self.entries:
28 start = entry.start
29 if start.year == now.year:
30 total += (entry.end - start).seconds
31 return total
32
33 def month(self):
34 total = 0
35 now = datetime.now()
36 for entry in self.entries:
37 start = entry.start
38 if start.month == now.month and start.year == now.year:
39 total += (entry.end - start).seconds
40 return total
41
42 def week(self):
43 total = 0
44 now = datetime.now()
45 tweek = now.strftime('%W')
46 for entry in self.entries:
47 start = entry.start
48 if start.strftime('%W') == tweek and start.year == now.year:
49 total += (entry.end - start).seconds
50 return total
51
52 def day(self):
53 total = 0
54 now = datetime.now()
55 for entry in self.entries:
56 start = entry.start
57 if start.month == now.month and start.year == now.year and start.day == now.day:
58 total += (entry.end - start).seconds
59 return total
60
61
62 class Entry:
63
64 def __init__(self, id, project_id, start, end, desc):
65 self.id = id
66 self.project_id = project_id
67 self.start = start
68 self.end = end
69 self.desc = desc
70
71 def duration(self):
72 return (self.end - self.start)
73
74 def __str__(self):
75 return ("[%s | %s | %s | %s | %s]" %
76 (self.id, self.project_id, self.start, self.end, self.desc))
77
78 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)