Commit fe485b5f authored by fred's avatar fred
Browse files

schedule: define day start hour as a variable

parent 15e8f6eb
......@@ -50,6 +50,8 @@ class Emission(models.Model):
class Schedule(models.Model):
DAY_HOUR_START = 6
WEEK_CHOICES = (
(0b1111, 'Every week'),
(0b0001, 'First week'),
......@@ -66,16 +68,16 @@ class Schedule(models.Model):
def get_weekday(self):
weekday = self.datetime.weekday() + 7
if self.datetime.time() < datetime.time(5, 0):
if self.datetime.time() < datetime.time(self.DAY_HOUR_START, 0):
weekday -= 1
weekday %= 7
return weekday
def is_on_weekday(self, day): # day is [1..7]
if self.datetime >= datetime.datetime(2007, 1, day, 5, 0) and \
self.datetime < datetime.datetime(2007, 1, day+1, 5, 0):
self.datetime < datetime.datetime(2007, 1, day+1, self.DAY_HOUR_START, 0):
return True
if day == 7 and self.datetime < datetime.datetime(2007, 1, 1, 5, 0):
if day == 7 and self.datetime < datetime.datetime(2007, 1, 1, self.DAY_HOUR_START, 0):
# special case for Sunday nights
return True
return False
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment