Skip to content

Commit

Permalink
Fix an issue seen when using time limits and start_period: today
Browse files Browse the repository at this point in the history
Fixes: #6
  • Loading branch information
badguy99 committed Apr 25, 2020
1 parent 31fe74f commit 1783f9d
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions apps/octoblock/octoblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,41 @@ def period_and_cost_callback(self, kwargs):
'same configuration block', level='ERROR')
now = datetime.datetime.now()
if start_period == 'today':
if now.time() < datetime.time(23, 30, 0):
if limit_end:
try:
datetime.datetime.strptime(limit_end, "%H:%M")
except ValueError:
self.log('end_time not in correct HH:MM format',
level='ERROR')
if limit_end:
try:
datetime.datetime.strptime(limit_end, "%H:%M")
except ValueError:
self.log('end_time not in correct HH:MM format',
level='ERROR')

limit_end = (datetime.date.today().isoformat() + 'T' +
limit_end + ':00')
if limit_start:
try:
datetime.datetime.strptime(limit_start, "%H:%M")
except ValueError:
self.log('start_time not in correct HH:MM format',
level='ERROR')
limit_end_t = limit_end
limit_end = (datetime.date.today().isoformat() + 'T' +
limit_end_t + ':00')
if now.time() >= datetime.time(23, 30, 0):
limit_end = ((datetime.date.today() +
datetime.timedelta(days=1)).isoformat() +
'T' + limit_end_t + ':00')
if limit_start:
try:
datetime.datetime.strptime(limit_start, "%H:%M")
except ValueError:
self.log('start_time not in correct HH:MM format',
level='ERROR')

d = (datetime.date.today().isoformat() + 'T' +
limit_start + ':00')
else:
d = datetime.date.today().isoformat() + 'T00:00:00'
d = (datetime.date.today().isoformat() + 'T' +
limit_start + ':00')
if now.time() >= datetime.time(23, 30, 0):
d = ((datetime.date.today() +
datetime.timedelta(days=1)).isoformat() +
'T' + limit_start + ':00')
else:
d = ((datetime.date.today() +
datetime.timedelta(days=1)).isoformat() +
'T00:00:00')
if now.time() < datetime.time(23, 30, 0):
d = datetime.date.today().isoformat() + 'T00:00:00'
else:
d = ((datetime.date.today() +
datetime.timedelta(days=1)).isoformat() +
'T00:00:00')

elif start_period == 'now':
d = now.isoformat()
else:
Expand Down

0 comments on commit 1783f9d

Please sign in to comment.