Advertisement
KeepCoding

CountWorkingDays

Feb 16th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. namespace P01CountWorkingDays
  7. {
  8.     class Program
  9.     {
  10.         private static string input1;
  11.         private static string input2;
  12.         private static string format;
  13.         private static DateTime startDate;
  14.         private static DateTime endDate;
  15.         private static DateTime[] holidays = new DateTime[]
  16.             {
  17.                 new DateTime(1, 12, 24), // godina, mesec, den
  18.                 new DateTime(1, 12, 25),
  19.                 new DateTime(1, 12, 26),
  20.                 new DateTime(1, 01, 01),
  21.                 new DateTime(1, 03, 03),
  22.                 new DateTime(1, 05, 01),
  23.                 new DateTime(1, 05, 06),
  24.                 new DateTime(1, 05, 24),
  25.                 new DateTime(1, 09, 06),
  26.                 new DateTime(1, 09, 22),
  27.                 new DateTime(1, 11, 01),
  28.             };
  29.  
  30.         static void Main(string[] args)
  31.         {
  32.             input1 = Console.ReadLine().Trim();
  33.             input2 = Console.ReadLine().Trim();
  34.             format = "dd-MM-yyyy";
  35.  
  36.             startDate = DateTime.ParseExact(input1, format, CultureInfo.InvariantCulture);
  37.             endDate = DateTime.ParseExact(input2, format, CultureInfo.InvariantCulture);
  38.             //RunWithErrors();
  39.  
  40.             int workindDays = 0;
  41.  
  42.             for (DateTime day = startDate; day <= endDate; day = day.AddDays(1))
  43.             {
  44.                 DayOfWeek dayOfWeek = day.DayOfWeek;
  45.                 DateTime tempDate = new DateTime(1, day.Month, day.Day);
  46.                 if (!holidays.Contains(tempDate) && !dayOfWeek.Equals(DayOfWeek.Sunday) && !dayOfWeek.Equals(DayOfWeek.Saturday))
  47.                 {
  48.                     workindDays += 1;
  49.                 }
  50.             }
  51.             Console.WriteLine(workindDays);
  52.  
  53.             //main ends here
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement