Skip to content

Commit

Permalink
Merge pull request #99 from drodger/master
Browse files Browse the repository at this point in the history
Prevent divide by zero error.
  • Loading branch information
llazzaro committed Jan 15, 2015
2 parents e2c9968 + 837f5d7 commit b43d638
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions schedule/templatetags/scheduletags.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,14 @@ def _cook_occurrences(period, occs, width, height):
w = width // o.max
o.width = w - 2
o.left = w * o.level
o.top = int(height * ((o.real_start - period.start).seconds / (period.end - period.start).seconds))
o.height = int(height * ((o.real_end - o.real_start).seconds / (period.end - period.start).seconds))
o.height = min(o.height, height - o.top) # trim what extends beyond the area
diff_in_seconds = (period.end - period.start).seconds
if diff_in_seconds:
o.top = int(height * ((o.real_start - period.start).seconds / diff_in_seconds))
o.height = int(height * ((o.real_end - o.real_start).seconds / diff_in_seconds))
else:
o.top = int(height * ((o.real_start - period.start).seconds / (24*60*60)))
o.height = int(height * ((o.real_end - o.real_start).seconds / (24*60*60)))
o.height = min(o.height, height - o.top) # trim what extends beyond the area
return display_occs


Expand All @@ -296,7 +301,10 @@ def _cook_slots(period, increment, width, height):
height - height of the table (px)
"""
tdiff = datetime.timedelta(minutes=increment)
num = (period.end - period.start).seconds // tdiff.seconds
if (period.end - period.start).seconds:
num = (period.end - period.start).seconds // tdiff.seconds
else:
num = 24 # hours in a day
s = period.start
slots = []
for i in range(num):
Expand Down

0 comments on commit b43d638

Please sign in to comment.