Commit 1f781797 authored by fred's avatar fred

adjust time of dawn

parent 36330815
...@@ -40,22 +40,24 @@ PODCAST_SOUND_QUALITY_LIST = ( ...@@ -40,22 +40,24 @@ PODCAST_SOUND_QUALITY_LIST = (
class WeekdayMixin(object): class WeekdayMixin(object):
DAY_HOUR_START = 5 DAY_HOUR_START = 4
DAY_MINUTE_START = 30
def get_weekday(self): def get_weekday(self):
weekday = self.datetime.weekday() + 7 weekday = self.datetime.weekday() + 7
if self.datetime.time() < datetime.time(self.DAY_HOUR_START, 0): if self.datetime.time() < datetime.time(self.DAY_HOUR_START, self.DAY_MINUTE_START):
weekday -= 1 weekday -= 1
weekday %= 7 weekday %= 7
return weekday return weekday
def is_on_weekday(self, day): # day is [1..7] def is_on_weekday(self, day): # day is [1..7]
week_day = self.datetime.weekday() week_day = self.datetime.weekday()
if self.datetime.hour < self.DAY_HOUR_START: if (self.datetime.hour, self.datetime.minute) < (self.DAY_HOUR_START, self.DAY_MINUTE_START):
week_day -= 1 week_day -= 1
week_day = (week_day % 7) + 1 week_day = (week_day % 7) + 1
if hasattr(self, 'episode'): if hasattr(self, 'episode'):
if self.datetime.hour < self.DAY_HOUR_START and self.end_datetime.hour > self.DAY_HOUR_START: if (self.datetime.hour, self.datetime.minute) < (self.DAY_HOUR_START, self.DAY_MINUTE_START) and \
(self.end_datetime.hour, self.end_datetime.minute) >= (self.DAY_HOUR_START, self.DAY_MINUTE_START):
if (self.end_datetime.weekday()+1) == day: if (self.end_datetime.weekday()+1) == day:
return True return True
return week_day == day return week_day == day
...@@ -287,7 +289,7 @@ class Schedule(models.Model, WeekdayMixin): ...@@ -287,7 +289,7 @@ class Schedule(models.Model, WeekdayMixin):
def matches(self, dt): def matches(self, dt):
weekday = dt.weekday() weekday = dt.weekday()
if dt.hour < self.DAY_HOUR_START: if (dt.hour, dt.minute) < (self.DAY_HOUR_START, self.DAY_MINUTE_START):
weekday -= 1 weekday -= 1
if weekday != self.get_weekday(): if weekday != self.get_weekday():
return False return False
......
...@@ -56,7 +56,7 @@ def whatsonair(): ...@@ -56,7 +56,7 @@ def whatsonair():
now = datetime.now() now = datetime.now()
# get program of today minus a few hours, as radio days are not from # get program of today minus a few hours, as radio days are not from
# midnight to midnigth but from 5am to 5am # midnight to midnigth but from 5am to 5am
program = day_program(now - timedelta(hours=Schedule.DAY_HOUR_START), program = day_program(now - timedelta(hours=Schedule.DAY_HOUR_START) + timedelta(minutes=Schedule.DAY_MINUTE_START),
prefetch_sounds=False, prefetch_categories=False, include_nonstop=False) prefetch_sounds=False, prefetch_categories=False, include_nonstop=False)
program = [x for x in program if not x.datetime > now] program = [x for x in program if not x.datetime > now]
...@@ -220,7 +220,7 @@ def period_program(date_start, date_end, prefetch_sounds=True, ...@@ -220,7 +220,7 @@ def period_program(date_start, date_end, prefetch_sounds=True,
# last step is adding nonstop zones between slots # last step is adding nonstop zones between slots
nonstops = list(Nonstop.objects.all().order_by('start')) nonstops = list(Nonstop.objects.all().order_by('start'))
nonstops = [x for x in nonstops if x.start != x.end] nonstops = [x for x in nonstops if x.start != x.end]
dawn = time(Schedule.DAY_HOUR_START, 0) dawn = time(Schedule.DAY_HOUR_START, Schedule.DAY_MINUTE_START)
try: try:
first_of_the_day = [x for x in nonstops if x.start <= dawn][-1] first_of_the_day = [x for x in nonstops if x.start <= dawn][-1]
nonstops = nonstops[nonstops.index(first_of_the_day):] + nonstops[:nonstops.index(first_of_the_day)] nonstops = nonstops[nonstops.index(first_of_the_day):] + nonstops[:nonstops.index(first_of_the_day)]
......
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