dayByAddingDays() public static method

public static dayByAddingDays ( String day, int days ) : String
day String
days int
return String
Ejemplo n.º 1
0
        // checks to see if a path is valid. used by route finding
        private bool validPath(String[] path, FlightTime start, String day, int tolerance)
        {
            Route      rte;
            FlightTime currentTime = (FlightTime)start.Clone();
            String     currentDay  = day;

            Flight[] flts;

            for (int i = 0; i < (path.Length - 1); i++)
            {
                rte = routesForParameters(path[i], path[i + 1])[0];
                if (rte.hasFlightsForTime(currentTime, currentDay, tolerance))
                {
                    flts        = rte.flightsForTime(currentTime, currentDay, tolerance);
                    currentTime = (FlightTime)flts[0].Arrival.Clone();
                    if (currentTime.nextDay)
                    {
                        currentTime.nextDay = false;
                        currentDay          = FlightTime.dayByAddingDays(day, 1);
                    }
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        // returns flights that match parameters
        public Flight[] flightsForTime(FlightTime flttime, String fltday, int tolerance)
        {
            // day index, 0 is monday, etc.
            // tolerance is in minutes
            // returns null if not found

            ArrayList  flights = new ArrayList(0);
            FlightTime time    = (FlightTime)flttime.Clone();
            String     day     = (String)fltday.Clone();

            if (time.nextDay)
            {
                day          = FlightTime.dayByAddingDays(day, 1);
                time.nextDay = false;
            }

            time.addMinutes(tolerance);

            foreach (Flight flt in __flights)
            {
                if (flt.hasFlightAtTime(time, day))
                {
                    flights.Add(flt);
                }
            }

            return((Flight[])flights.ToArray(typeof(Flight)));
        }
Ejemplo n.º 3
0
        // recursive magic to build the tree of flight paths
        private bool buildFlightTree(ref TreeNode <Flight> node, TreeNode <Flight> previous, Route[] routes, Route dest, int nextDestIndex, String day, int tolerance)
        {
            if (node.Value.Route == dest)
            {
                // success
                return(true);
            }
            else
            {
                TreeNode <Flight> currentNode;
                bool     something  = false;
                Flight[] connecting = connectingForFlight(node.Value, routes[nextDestIndex].Destination, day, tolerance);
                String   currentDay = (String)day.Clone();

                if (node.Value.Arrival.nextDay)
                {
                    currentDay = FlightTime.dayByAddingDays(day, 1);
                }

                foreach (Flight flt in connecting)
                {
                    currentNode = new TreeNode <Flight>(flt);
                    int ndi = nextDestIndex + 1;

                    if (ndi >= routes.Length)
                    {
                        ndi = routes.Length - 1;
                    }

                    if (buildFlightTree(ref currentNode, node, routes, dest, ndi, currentDay, tolerance))
                    {
                        node.Children.Add(currentNode);
                        if (!something)
                        {
                            something = true;
                        }
                    }
                }

                return(something);
            }
        }
Ejemplo n.º 4
0
        private bool buildMultiStopTree(String origin, String dest, String[] remainingNodes, String endDay, String day, ref TreeNode <String> current, TreeNode <String> previous)
        {
            if (remainingNodes.Length == 0)
            {
                if ((pathsForOriginDest(previous.Value, current.Value, day, 0).Count > 0) &&
                    (current.Value.ToLower().Equals(dest.ToLower())))
                {
                    if (endDay == null)
                    {
                        return(true);
                    }
                    else if (day.ToLower().Equals(endDay.ToLower()))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            if (previous != null)
            {
                if (pathsForOriginDest(previous.Value, current.Value, day, 0).Count == 0)
                {
                    return(false);
                }
            }


            // obviously if those fail, something has to be done
            bool something = false;

            String currentDay = (String)day.Clone();

            if (previous != null)
            {
                Route[] rtes = routesForParameters(previous.Value, current.Value);
                if (rtes.Length > 0)
                {
                    Route    rte  = rtes[0];
                    Flight[] flts = rte.flightsForTime(new FlightTime(0, 0, false), day, 0);

                    foreach (Flight flt in flts)
                    {
                        if (flt.Arrival.nextDay)
                        {
                            currentDay = FlightTime.dayByAddingDays(currentDay, 1);
                            break;
                        }
                    }

                    currentDay = FlightTime.dayByAddingDays(currentDay, 1);
                }
                else
                {
                    return(false);
                }
            }



            TreeNode <String> node;

            for (int i = 0; i < remainingNodes.Length; i++)
            {
                node = new TreeNode <string>(remainingNodes[i]);

                if (buildMultiStopTree(origin, dest, remainingByTakingOut(remainingNodes, remainingNodes[i]), endDay, currentDay, ref node, current))
                {
                    current.Children.Add(node);
                    if (!something)
                    {
                        something = true;
                    }
                }
            }

            return(something);
        }