public void TestNoWeekEnd()
        {
            DateTime startDate = new DateTime(2014, 12, 1);
            int      count     = 10;

            DateTime result = WorkDayCalculator.Calculate(startDate, count, null);

            Assert.AreEqual(startDate.AddDays(count - 1), result);
        }
        public void TestWeekendsBeforePeriod()
        {
            DateTime startDate = new DateTime(2017, 4, 20);
            int      count     = 5;

            WeekEnd[] weekends = new WeekEnd[1]
            {
                new WeekEnd(new DateTime(2017, 4, 10), new DateTime(2017, 4, 15))
            };

            DateTime result = WorkDayCalculator.Calculate(startDate, count, weekends);

            Assert.IsTrue(result.Equals(new DateTime(2017, 4, 24)));
        }
        public void TestWeekendsAfterPeriod()
        {
            DateTime startDate = new DateTime(2017, 4, 20);
            int      count     = 7;

            WeekEnd[] weekends = new WeekEnd[1]
            {
                new WeekEnd(new DateTime(2017, 4, 29), new DateTime(2017, 4, 30))
            };

            DateTime result = WorkDayCalculator.Calculate(startDate, count, weekends);

            Assert.IsTrue(result.Equals(new DateTime(2017, 4, 26)));
        }
        public void TestOneWeekendsInside()
        {
            DateTime startDate = new DateTime(2017, 4, 21);
            int      count     = 5;

            WeekEnd[] weekends = new WeekEnd[1]
            {
                new WeekEnd(new DateTime(2017, 4, 23), new DateTime(2017, 4, 23))
            };

            DateTime result = WorkDayCalculator.Calculate(startDate, count, weekends);

            Assert.IsTrue(result.Equals(new DateTime(2017, 4, 26)));
        }
        public void TestWeekendAfterEnd()
        {
            DateTime startDate = new DateTime(2017, 4, 21);
            int      count     = 5;

            WeekEnd[] weekends = new WeekEnd[2]
            {
                new WeekEnd(new DateTime(2017, 4, 23), new DateTime(2017, 4, 25)),
                new WeekEnd(new DateTime(2017, 4, 29), new DateTime(2017, 4, 29))
            };

            DateTime result = WorkDayCalculator.Calculate(startDate, count, weekends);

            Assert.IsTrue(result.Equals(new DateTime(2017, 4, 28)));
        }
        public void TestBeginAndEndIn1dayWeekends()
        {
            DateTime startDate = new DateTime(2017, 4, 13);
            int      count     = 3;

            WeekEnd[] weekends = new WeekEnd[2]
            {
                new WeekEnd(new DateTime(2017, 4, 13), new DateTime(2017, 4, 13)),
                new WeekEnd(new DateTime(2017, 4, 18), new DateTime(2017, 4, 18))
            };

            DateTime result = WorkDayCalculator.Calculate(startDate, count, weekends);

            Assert.IsTrue(result.Equals(new DateTime(2017, 4, 16)));
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            DateTime startDate = new DateTime(2017, 4, 21);
            int      dayCount  = 7;

            WeekEnd[] weekends = new WeekEnd[2]
            {
                new WeekEnd(new DateTime(2017, 4, 23), new DateTime(2017, 4, 25)),
                new WeekEnd(new DateTime(2017, 4, 29), new DateTime(2017, 4, 29))
            };

            WorkDayCalculator wdk = new WorkDayCalculator();

            wdk.Calculate(startDate, dayCount, weekends);

            Console.ReadKey();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            try
            {
                string[]          Weekends   = new string[2];
                WorkDayCalculator calculator = new WorkDayCalculator();

                Console.Write("Start date:");
                DateTime Date = Convert.ToDateTime(Console.ReadLine());

                Console.Write("Duration, day(s):");
                uint Duration = UInt32.Parse(Console.ReadLine());

                Console.Write("Weekends 1:");
                string weekends = Console.ReadLine();
                if (weekends != "0")
                {
                    Weekends = weekends.Split('-');
                }
                DateTime  startWeek = Convert.ToDateTime(Weekends[0]);
                DateTime  endtWeek  = Convert.ToDateTime(Weekends[1]);
                WeekEnd[] weekEnd   = new WeekEnd[]
                {
                    new WeekEnd(startWeek, endtWeek)
                };

                Console.Write("Weekends 2:");
                weekends = Console.ReadLine();
                if (weekends != "0")
                {
                    Weekends  = weekends.Split('-');
                    startWeek = Convert.ToDateTime(Weekends[0]);
                    endtWeek  = Convert.ToDateTime(Weekends[1]);
                    Array.Resize(ref weekEnd, 2);
                    weekEnd[1] = new WeekEnd(startWeek, endtWeek);
                }

                Console.WriteLine($"At the exit there should be: {calculator.Calculate(Date, Duration, weekEnd).ToShortDateString()}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }