From eab72df9ac51cfc0ae3fe4f3a0850c055c1d7e40 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Sun, 26 Feb 2017 11:24:46 +0100 Subject: [PATCH] fix error calculating prize --- billard/utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/billard/utils.py b/billard/utils.py index 328adff..d93156d 100644 --- a/billard/utils.py +++ b/billard/utils.py @@ -16,7 +16,7 @@ def get_prize_for(start, end, pph=0, hh_start=None, hh_end=None, pphh=0): if end <= start: raise ValueError('end date must be after start date') 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() t = start.time() 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): pps = pph / 3600 d = date.today() - t = (datetime.combine(d, end) - datetime.combine(d, start)).seconds - return round((pps * t), 1) + seconds = 0 + if isinstance(start, datetime): + seconds = (end - start).seconds + else: + seconds = (datetime.combine(d, end) - datetime.combine(d, start)).seconds + return round((pps * seconds), 1)