Пример #1
0
        // Task to think about: how to combine the next two methods into one or at least reduce the amount of duplicated lines?
        public int TimeToNextDepartureFromOrigin(RouteStation station, DateTime currentDt)
        {
            int currentTime = currentDt.Hour * 60 + currentDt.Minute;

            if (TimeHelpers.IsTimeWithinInterval(currentTime, FirstDepartureFromOrigin(station),
                                                 LastDepartureFromOrigin(station)))
            {
                int difference   = TimeHelpers.Difference(FirstDepartureFromOrigin(station), currentTime);
                int passedTrains = difference / Interval;
                if (difference % Interval != 0)
                {
                    passedTrains++;
                }

                int timeOfNextDeparture = TimeHelpers.AddMinutes(FirstDepartureFromOrigin(station),
                                                                 passedTrains * Interval);

                return(TimeHelpers.Difference(currentTime, timeOfNextDeparture));
            }
            else
            {
                return(TimeHelpers.Difference(currentTime, FirstDepartureFromOrigin(station)));
            }
        }
Пример #2
0
 public int LastDepartureFromDest(RouteStation station)
 {
     return(TimeHelpers.AddMinutes(EndTime, station.TimeFromDest));
 }
Пример #3
0
 public int FirstDepartureFromOrigin(RouteStation station)
 {
     return(TimeHelpers.AddMinutes(StartTime, station.TimeFromOrigin));
 }