Пример #1
0
        static void Main(string[] args)
        {
            //
            var Weekend = new WeekEnd(new DateTime(2017, 4, 23), new DateTime(2017, 4, 25));
            var EndDate = WorkDayCalculator.Calculate(new DateTime(2017, 4, 21), 5, Weekend);

            Console.WriteLine(EndDate);
            Console.ReadKey();
        }
Пример #2
0
        static void Main(string[] args)
        {
            int               count     = 10;
            DateTime          startDate = new DateTime(2021, 12, 1);
            WorkDayCalculator wdc       = new WorkDayCalculator();
            var               res       = wdc.Calculate(startDate, count, null);

            Console.WriteLine(res);
            int count1 = 10;

            WeekEnd[] weekends = new WeekEnd[1]
            {
                new WeekEnd(new DateTime(2021, 4, 23), new DateTime(2021, 4, 25))
            };
            DateTime          startDate1 = new DateTime(2021, 4, 21);
            WorkDayCalculator wdc1       = new WorkDayCalculator();
            var res1 = wdc.Calculate(startDate1, count1, weekends);

            //Console.WriteLine(res1);
            //List<int> ints = new List<int> { 1, 2, 3, 4, 5, 6, 7};
            //List<int> list = new List<int> {12, 13, 14};
            ////ints[0] = 5;
            //foreach (var item in ints)
            //{
            //    Console.Write(item + " ");
            //}


            //var count = 0;
            //for (int i = 0; i < ints.Count; i++)
            //{
            //    if (ints[i] == 3)
            //    {
            //        var l = Enumerable.Range(list[0], list.Count).ToList();
            //        l.Sort();
            //        foreach (var item in l)
            //        {
            //            ints.Insert(count,item);
            //        }
            //        break;
            //    }
            //    count++;
            //}

            //Console.WriteLine();
            //Console.ForegroundColor = ConsoleColor.Red;
            //foreach (var item in ints)
            //{
            //    Console.Write(item + " ");
            //}


            Console.Read();
        }
Пример #3
0
        public void WeekendsBeforeStartDay()
        {
            DateTime startDate = new DateTime(2020, 4, 8);
            int      count     = 5;

            WeekEnd[] weekends = new WeekEnd[1]
            {
                new WeekEnd(new DateTime(2020, 4, 6), new DateTime(2020, 4, 7))
            };
            DateTime result = new WorkDayCalculator.WorkDayCalculator().Calculate(startDate, count, weekends);

            Assert.IsTrue(result.Equals(new DateTime(2020, 4, 12)));
        }
Пример #4
0
        static void Main(string[] args)
        {
            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, 29))
            };

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

            Console.WriteLine(result);
            Console.ReadKey();
        }
Пример #5
0
        public void StartDayInsideWeekendsperiod()
        {
            DateTime startDate = new DateTime(2020, 4, 8);
            int      count     = 5;

            WeekEnd[] weekends = new WeekEnd[3]
            {
                new WeekEnd(new DateTime(2020, 4, 6), new DateTime(2020, 4, 10)),
                new WeekEnd(new DateTime(2020, 4, 13), new DateTime(2020, 4, 16)),
                new WeekEnd(new DateTime(2020, 4, 17), new DateTime(2020, 4, 17))
            };
            DateTime result = new WorkDayCalculator.WorkDayCalculator().Calculate(startDate, count, weekends);

            Assert.IsTrue(result.Equals(new DateTime(2020, 4, 20)));
        }
 protected void Page_PreRender(object sender, EventArgs e)
 {
     if (!WeekListChecked)
     {
         // Initialize week and weekend selectors
         WeekDays.ClearSelection();
         foreach (ListItem li in WeekDays.Items)
         {
             li.Selected = true;
         }
         WeekEnd.ClearSelection();
         foreach (ListItem li in WeekEnd.Items)
         {
             li.Selected = true;
         }
     }
 }
Пример #7
0
        public void NormalPath()
        {
            DateTime startDate = new DateTime(2020, 4, 8);
            int      count     = 5;

            WeekEnd[] weekends = new WeekEnd[5]
            {
                new WeekEnd(new DateTime(2020, 4, 9), new DateTime(2020, 4, 10)),
                new WeekEnd(new DateTime(2020, 4, 12), new DateTime(2020, 4, 17)),
                new WeekEnd(new DateTime(2020, 4, 18), new DateTime(2020, 4, 20)),
                new WeekEnd(new DateTime(2020, 4, 21), new DateTime(2020, 4, 21)),
                new WeekEnd(new DateTime(2020, 4, 25), new DateTime(2020, 4, 26)),
            };
            DateTime result = new WorkDayCalculator.WorkDayCalculator().Calculate(startDate, count, weekends);

            Assert.IsTrue(result.Equals(new DateTime(2020, 4, 24)));
        }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        if (!WeekListChecked)
        {
            // Initialize week and weekend selectors
            WeekDays.ClearSelection();
            foreach (ListItem li in WeekDays.Items)
            {
                li.Selected = true;
            }
            WeekEnd.ClearSelection();
            foreach (ListItem li in WeekEnd.Items)
            {
                li.Selected = true;
            }
        }
    }
Пример #9
0
 public virtual string Dump()
 {
     return(String.Format(@" ID={0} Week={1} From={2} To={3}\n 
                            PlannedHours={4} AddCharges={5} WorkingHours={6} ContractHours={7}\n
                             Saldo={8} AllIn={9} CustomEdit={10}, OrderHWGR={11}", new object[] { EmployeeID, WeekNumber, WeekBegin.ToShortDateString(),
                                                                                                  WeekEnd.ToShortDateString(), PlannedHours, AdditionalCharge, WorkingHours, ContractHours, Saldo, AllIn, CustomEdit, OrderHWGR }));
 }
Пример #10
0
    private async Task SelectNextWeekAsync()
    {
        DateTime dayOnNextWeek = WeekEnd.AddDays(1);

        await SetWeekByDayAsync(dayOnNextWeek);
    }
Пример #11
0
 /// <summary>
 /// Adds the given number of business days to the <see cref="DateTime"/>.
 /// </summary>
 /// <param name="current">The date to be changed.</param>
 /// <param name="days">Number of business days to be added.</param>
 /// <param name="excludeWeekEnd">Exclude Weekend days.</param>
 /// <returns>A <see cref="DateTime"/> increased by a given number of business days.</returns>
 public static DateTime AddBusinessDays(this DateTime current, int days, WeekEnd excludeWeekEnd)
 {
     return(AddBusinessDays(current, days, null, excludeWeekEnd));
 }
Пример #12
0
        /// <summary>
        /// Adds the given number of business days to the <see cref="DateTime"/>.
        /// </summary>
        /// <param name="current">The date to be changed.</param>
        /// <param name="days">Number of business days to be added.</param>
        /// <param name="holidays">Days to exclude by holidays</param>
        /// <param name="excludeWeekEnd">Exclude Weekend days.</param>
        /// <returns>A <see cref="DateTime"/> increased by a given number of business days.</returns>
        public static DateTime AddBusinessDays(this DateTime current, int days, DateTime[] holidays, WeekEnd excludeWeekEnd)
        {
            var sign         = Math.Sign(days);
            var unsignedDays = Math.Abs(days);

            for (int i = 0; i < unsignedDays; i++)
            {
                do
                {
                    current = current.AddDays(sign);
                }while ((current.DayOfWeek == DayOfWeek.Saturday && (excludeWeekEnd & WeekEnd.Saturday) == WeekEnd.Saturday) ||
                        (current.DayOfWeek == DayOfWeek.Sunday && (excludeWeekEnd & WeekEnd.Sunday) == WeekEnd.Sunday) ||
                        (holidays != null && holidays.Contains(current)));
            }

            return(current);
        }