private static IEnumerable <int> MakeRelativeScheduleWithinCutoff(BusStopRouteDaySchedule daySchedule, DateTimeOffset currentTime)
        {
            // Is there a better condition for this, i.e. involving a check whether there are 24hr+ time spans in the schedule?
            var timeOfDay = daySchedule.Days == DaysOfWeek.NightOwl &&
                            currentTime.TimeOfDay.Hours < 4
                ? currentTime.TimeOfDay.Add(TimeSpan.FromDays(1))
                : currentTime.TimeOfDay;

            var scheduleCutoff = timeOfDay.Add(TimeSpan.FromMinutes(20));

            return(daySchedule.Times.Where(ts => ts > scheduleCutoff)
                   .Select(ts => (int)ts.Subtract(timeOfDay).TotalMinutes));
        }
Esempio n. 2
0
        private static IEnumerable <int> MakeRelativeScheduleWithinCutoff(BusStopRouteDaySchedule daySchedule, DateTimeOffset currentTime)
        {
            var oneDay     = TimeSpan.FromDays(1);
            var latestTime = daySchedule.Times.Last();
            var timeOfDay  = latestTime.Days == 1 && currentTime.TimeOfDay < latestTime - oneDay
                ? currentTime.TimeOfDay + oneDay
                : currentTime.TimeOfDay;

            // Truncate any seconds on timeOfDay so that we don't get off-by-one errors
            // when converting a scheduled time with a seconds component to minutesFromNow and back.
            timeOfDay -= TimeSpan.FromSeconds(timeOfDay.Seconds);

            var scheduleCutoff = timeOfDay + TimeSpan.FromMinutes(20);

            return(daySchedule.Times.Where(ts => ts > scheduleCutoff)
                   .Select(ts => (int)(ts - timeOfDay).TotalMinutes));
        }