forked from phynfo/LiquidDemocracy-XXS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
50 lines (44 loc) · 1.42 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from time import strptime
from datetime import datetime
import re
def date_diff(older, newer):
"""
Returns a humanized string representing time difference
The output rounds up to days, hours, minutes, or seconds.
4 days 5 hours returns '4 Tage'
0 days 4 hours 3 minutes returns '4 Stunden', etc...
"""
timeDiff = newer - older
days = timeDiff.days
hours = timeDiff.seconds/3600
minutes = timeDiff.seconds%3600/60
seconds = timeDiff.seconds%3600%60
str = ""
tStr = ""
if days > 0:
if days == 1: tStr = "Tag"
else: tStr = "Tagen"
str = str + "%s %s" %(days, tStr)
return str
elif hours > 0:
if hours == 1: tStr = "Stunde"
else: tStr = "Stunden"
str = str + "%s %s" %(hours, tStr)
return str
elif minutes > 0:
if minutes == 1:tStr = "Minute"
else: tStr = "Minuten"
str = str + "%s %s" %(minutes, tStr)
return str
elif seconds > 0:
if seconds == 1:tStr = "Sekunden"
else: tStr = "Sekunde"
str = str + "%s %s" %(seconds, tStr)
return str
else:
return None
def compact(s):
''' return the first few words of the text s in order to produce
a short description of an entry's or comment's text '''
s2 = filter(lambda c: c!='\n', s)
return re.match(r'.*\s',s2).string + ' ... '