]> git.0d.be Git - django-panik-emissions.git/commitdiff
adjust time of dawn
authorFrédéric Péters <fpeters@0d.be>
Wed, 21 Oct 2020 16:07:02 +0000 (18:07 +0200)
committerFrédéric Péters <fpeters@0d.be>
Wed, 21 Oct 2020 16:07:02 +0000 (18:07 +0200)
emissions/models.py
emissions/utils.py

index c6b7f99b967c8b83d87c18415ce03d363e22eb6e..d4123ae5d22a81c322d846192fa6c53facac7f92 100644 (file)
@@ -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):
         weekday = self.datetime.weekday() + 7
 
     def get_weekday(self):
         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 %= 7
         return weekday
 
     def is_on_weekday(self, day): # day is [1..7]
         week_day = self.datetime.weekday()
             weekday -= 1
         weekday %= 7
         return weekday
 
     def is_on_weekday(self, day): # day is [1..7]
         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 = (week_day % 7) + 1
         if hasattr(self, 'episode'):
             week_day -= 1
         week_day = (week_day % 7) + 1
         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:
                     return True
         return week_day == day
                 if (self.end_datetime.weekday()+1) == day:
                     return True
         return week_day == day
@@ -287,7 +289,7 @@ class Schedule(models.Model, WeekdayMixin):
 
     def matches(self, dt):
         weekday = dt.weekday()
 
     def matches(self, dt):
         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
         if weekday != self.get_weekday():
             return False
             weekday -= 1
         if weekday != self.get_weekday():
             return False
index def59d6353c77cc01baa342b6c170c89e2c979fd..cec0f63bdb31b1329e4cf9a1038e90b371f9bf3d 100644 (file)
@@ -56,7 +56,7 @@ def whatsonair():
     now = datetime.now()
     # get program of today minus a few hours, as radio days are not from
     # midnight to midnigth but from 5am to 5am
     now = datetime.now()
     # get program of today minus a few hours, as radio days are not from
     # 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)
     program = [x for x in program if not x.datetime > now]
 
             prefetch_sounds=False, prefetch_categories=False, include_nonstop=False)
     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,
     # last step is adding nonstop zones between slots
     nonstops = list(Nonstop.objects.all().order_by('start'))
     nonstops = [x for x in nonstops if x.start != x.end]
     # last step is adding nonstop zones between slots
     nonstops = list(Nonstop.objects.all().order_by('start'))
     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:
         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)]
     try:
         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)]