summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
Diffstat (limited to 'program')
-rw-r--r--program/templatetags/timeslots.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/program/templatetags/timeslots.py b/program/templatetags/timeslots.py
new file mode 100644
index 0000000..9b83a80
--- /dev/null
+++ b/program/templatetags/timeslots.py
@@ -0,0 +1,22 @@
+from django import template
+
+register = template.Library()
+
+from datetime import datetime, time, timedelta
+
+@register.simple_tag
+def duration(start, end):
+ return 'style="height: %dpx"' % ((end-start).seconds/60)
+
+@register.simple_tag
+def duration_until(end):
+ start = datetime.combine(end.date(), time(6,0))
+ return 'style="height: %dpx"' % ((end-start).seconds/60)
+
+@register.simple_tag
+def duration_since(start):
+ if start.time()<time(0,0):
+ end = datetime.combine(start.date()+timedelta(days=1), time(6,0))
+ else:
+ end = datetime.combine(start.date(), time(6,0))
+ return 'style="height: %dpx"' % ((end-start).seconds/60) \ No newline at end of file