Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- class CalculateWorkingDays
- {
- static int currentYear = DateTime.Now.Year;
- static List<DateTime> holidays = new List<DateTime>
- {
- new DateTime(currentYear, 1, 1),
- new DateTime(currentYear, 3, 3),
- new DateTime(currentYear, 5, 1),
- new DateTime(currentYear, 5, 3),
- new DateTime(currentYear, 5, 6),
- new DateTime(currentYear, 5, 24),
- new DateTime(currentYear, 9, 22),
- new DateTime(currentYear, 12, 24),
- new DateTime(currentYear, 12, 25),
- new DateTime(currentYear, 12, 26),
- new DateTime(currentYear, 12, 31),
- };
- static void Main()
- {
- DateTime startDate = DateTime.Today;
- DateTime endDate = new DateTime(currentYear, 2, 17);
- CalculateWorkDays(startDate, endDate);
- }
- static void CalculateWorkDays(DateTime startDate, DateTime endDate)
- {
- int numberOfAllDays = (endDate - startDate).Days;
- // не е нужна
- //bool isHoliday = false;
- int numberOfWorkingDays = 0;
- for (int i = 0; i < numberOfAllDays; i++)
- {
- startDate = startDate.AddDays(1);
- if (startDate.DayOfWeek != DayOfWeek.Sunday && startDate.DayOfWeek != DayOfWeek.Saturday)
- {
- //for (int j = 0; j < holidays.Length; j++)
- //{
- // if (startDate == holidays[j])
- // {
- // isHoliday = true;
- // break;
- // }
- //}
- //if (!isHoliday)
- //{
- // numberOfWorkingDays++;
- //}
- //isHoliday = false;
- if (!holidays.Contains(startDate))
- {
- numberOfWorkingDays++;
- }
- }
- }
- Console.WriteLine("Number of working days:{0}",numberOfWorkingDays);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement