fix error calculating prize

This commit is contained in:
Robert Einsle 2017-02-26 11:24:46 +01:00
parent ce9e54f21d
commit eab72df9ac

View File

@ -16,7 +16,7 @@ def get_prize_for(start, end, pph=0, hh_start=None, hh_end=None, pphh=0):
if end <= start: if end <= start:
raise ValueError('end date must be after start date') raise ValueError('end date must be after start date')
prize = 0 prize = 0
if hh_start is not None and hh_end is not None: if hh_start is not None and hh_end is not None and pphh is not None:
d = start.date() d = start.date()
t = start.time() t = start.time()
end_date = end.date() end_date = end.date()
@ -52,5 +52,9 @@ def get_prize_for(start, end, pph=0, hh_start=None, hh_end=None, pphh=0):
def calculate_prize_for(start, end, pph=0): def calculate_prize_for(start, end, pph=0):
pps = pph / 3600 pps = pph / 3600
d = date.today() d = date.today()
t = (datetime.combine(d, end) - datetime.combine(d, start)).seconds seconds = 0
return round((pps * t), 1) if isinstance(start, datetime):
seconds = (end - start).seconds
else:
seconds = (datetime.combine(d, end) - datetime.combine(d, start)).seconds
return round((pps * seconds), 1)