Exemplo n.º 1
0
        public static bool IsOpen(string fullDate, Stores store, Storeschedules program)
        {
            Console.WriteLine(">>>>>>>>>>>>>>>Check if store " + store.Name + " is open at " + fullDate);
            //fullDate format: DD:MM:YY:HH:MM

            if (fullDate.Equals("closed"))
            {
                return(false);
            }

            string[] tokens = fullDate.Split(":");
            int      day, month, year;

            day   = Int32.Parse(tokens[0]);
            month = Int32.Parse(tokens[1]);
            year  = Int32.Parse(tokens[2]);

            string currentTime = tokens[3] + ":" + tokens[4];

            DateTime dateValue = new DateTime(year, month, day);
            string   DayOfWeek = dateValue.ToString("dddd");

            //verify if the store is open (for DayOfWeek)
            string interval = (string)program.GetType().GetProperty(DayOfWeek).GetValue(program, null);

            if (interval.Equals("closed"))
            {
                return(false);
            }
            string[] openClose = interval.Split("-");

            TimeSpan openTime  = TimeSpan.Parse(openClose[0]);
            TimeSpan closeTime = TimeSpan.Parse(openClose[1]);
            TimeSpan now       = TimeSpan.Parse(currentTime);

            if (now >= openTime && now <= closeTime)
            {
                Console.WriteLine("Store is open " + store.Name);
                return(true);
            }

            return(false);
        }