Permalink
Browse files

Only show departures in the next 2 hours

  • Loading branch information...
1 parent c633fff commit 88ff96f4ca86f23fed711f36e311e96cad07d350 @cnorthwood cnorthwood committed Jul 7, 2011
Showing with 7 additions and 3 deletions.
  1. +7 −3 molly/apps/places/providers/timetables.py
@@ -1,5 +1,5 @@
from collections import namedtuple, defaultdict
-from datetime import datetime, time
+from datetime import datetime, time, timedelta
from logging import getLogger
from operator import itemgetter
@@ -38,8 +38,12 @@ def midnight_4am(left, right):
continue
services = defaultdict(list)
- for stop in entity.scheduledstop_set.filter(
- Q(sta__gte=today.time()) | Q(sta__lt=time(4))):
+ if today.time() < time(22):
+ until = [Q(sta__gte=today.time()) | Q(std__gte=today.time()), Q(sta__lt=(today + timedelta(hours=2)).time()) | Q(std__lt=(today + timedelta(hours=2)).time())]
+ else:
+ until = [Q(sta__gte=today.time()) | Q(std__gte=today.time()) | Q(sta__lt=(today + timedelta(hours=2)).time()) | Q(std__lt=(today + timedelta(hours=2)).time())]
+
+ for stop in entity.scheduledstop_set.filter(*until):
if not stop.journey.runs_on(today.date()):
continue

0 comments on commit 88ff96f

Please sign in to comment.