         time:
           $lte: endTime
       ]
+    startDayQuery = {}
+    startDayQuery["JsonScheduleV1.schedule_days_runs.#{startDayOfWeek}"] = true
+    endDayQuery = {}
+    endDayQuery["JsonScheduleV1.schedule_days_runs.#{endDayOfWeek}"] = true
+    dayQuery =
+      $or: [
+        startDayQuery
+      ,
+        endDayQuery
+      ]
   else
     timeQuery =
       tiploc_code: tiploc
       time:
         $gte: startTime
         $lte: endTime
-
-  day = (date.getDay() + 6) % 7
-  dayQuery = {}
-  dayQuery["JsonScheduleV1.schedule_days_runs.#{day}"] = true
+    dayQuery["JsonScheduleV1.schedule_days_runs.#{startDayOfWeek}"] = true
   Schedules.find
     $and: [
       'JsonScheduleV1.schedule_segment.schedule_location':

  timeOffset or= 60
  getDateScheduleForTiploc(now, tiploc, timeOffset)

@getDateScheduleForTiploc = (date, tiploc, timeOffset) ->
  # Days runs starts with monday at index 0, javascript starts with sunday at
  # index 0. We need to shift it along
  m = moment(date)
  startTime = parseInt(m.format('HHmm'))
  endTime = parseInt(m.add('minutes', timeOffset).format('HHmm'))
  # Special after midnight case
  if endTime < startTime
    timeQuery =

    train.terminated = terminated == 'true'
  train

@getArrivalAndDepartureTimes = (currentTiploc, scheduleCursor, date) ->
  date or= new Date()
  date = moment(date)
  schedules = []
  scheduleCursor.forEach (rawSchedule) ->
    jsonScheduleV1 = rawSchedule.JsonScheduleV1
