Beispiel #1
0
        static void Main(string[] args)
        {
            string   startDateString = Console.ReadLine();
            string   endDateString   = Console.ReadLine();
            DateTime startDate       = DateTime.ParseExact(startDateString, "dd-MM-yyyy", CultureInfo.InvariantCulture);
            DateTime endDate         = DateTime.ParseExact(endDateString, "dd-MM-yyyy", CultureInfo.InvariantCulture);

            DateTime[] holidays = new DateTime[11];
            holidays[0]  = new DateTime(01, 01, 1);
            holidays[1]  = new DateTime(03, 03, 1);
            holidays[2]  = new DateTime(01, 05, 1);
            holidays[3]  = new DateTime(06, 05, 1);
            holidays[4]  = new DateTime(24, 05, 1);
            holidays[5]  = new DateTime(06, 09, 1);
            holidays[6]  = new DateTime(22, 09, 1);
            holidays[7]  = new DateTime(01, 11, 1);
            holidays[8]  = new DateTime(24, 12, 1);
            holidays[9]  = new DateTime(25, 12, 1);
            holidays[10] = new DateTime(26, 12, 1);

            int workingDaysCounter = 0;

            for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
            {
                DayOfWeek currentDay  = date.DayOfWeek;
                DateTime  currentDate = new DateTime(date.Day, date.Month, 1);
                if (!holidays.Contains(currentDate) && !currentDay.Equals(DayOfWeek.Saturday) &&
                    !currentDay.Equals(DayOfWeek.Sunday))
                {
                    workingDaysCounter++;
                }
            }

            Console.WriteLine(workingDaysCounter);
        }
Beispiel #2
0
        private string GetDistinctDate(DateTime now, int usWeekNumber)
        {
            DayOfWeek dt    = now.AddDays(1 - now.Day).DayOfWeek;
            int       check = dt.Equals(DayOfWeek.Friday) || dt.Equals(DayOfWeek.Saturday) ? 3 : 2;

            return(usWeekNumber > check || usWeekNumber == check && (now.DayOfWeek.Equals(DayOfWeek.Friday) || now.DayOfWeek.Equals(DayOfWeek.Saturday)) ? now.AddMonths(1).ToString("yyyyMM") : now.ToString("yyyyMM"));
        }
Beispiel #3
0
 /// <summary>
 /// Given a day of the week encoded as DayOfWeek enum (i.e. named integers):
 /// Sunday=0, Monday=1, Tuesday=2, ...Saturday=6,
 /// and a boolean indicating if we are on vacation--
 /// return a string in the form of "7:00" indicating when the alarm clock should ring.
 /// on weekends, the alarm should ring at "10:00", but
 /// on the weekdays, the alarm should ring at "7:00" unless we are on vacation,
 /// in which the alarm will then ring at "10:00" on the weekdays but "off" during the weekend.
 /// </summary>
 /// <param name="dayOfWeek"></param>
 /// <param name="vacation"></param>
 /// <returns>either: "7:00" or "10:00" or "off"</returns>
 public static string AlarmClock(DayOfWeek dayOfWeek, bool vacation)
 {
     if (vacation)
     {
         if (dayOfWeek.Equals(DayOfWeek.Sunday) || dayOfWeek.Equals(DayOfWeek.Saturday))
         {
             return("off");
         }
         else
         {
             return("10:00");
         }
     }
     else
     {
         if (dayOfWeek.Equals(DayOfWeek.Sunday) || dayOfWeek.Equals(DayOfWeek.Saturday))
         {
             return("10:00");
         }
         else
         {
             return("7:00");
         }
     }
 }
Beispiel #4
0
        protected internal string GetDistinctDate(int usWeekNumber)
        {
            DayOfWeek dt    = DateTime.Now.AddDays(1 - DateTime.Now.Day).DayOfWeek;
            int       check = dt.Equals(DayOfWeek.Friday) || dt.Equals(DayOfWeek.Saturday) ? 3 : 2;

            return(usWeekNumber > check || usWeekNumber == check && (DateTime.Now.DayOfWeek.Equals(DayOfWeek.Friday) || DateTime.Now.DayOfWeek.Equals(DayOfWeek.Saturday)) ? DateTime.Now.AddMonths(1).ToString("yyyyMM") : DateTime.Now.ToString("yyyyMM"));
        }
Beispiel #5
0
        /// <summary>
        /// Given a day of the week encoded as DayOfWeek enum (i.e. named integers):
        /// Sunday=0, Monday=1, Tuesday=2, ...Saturday=6,
        /// and a boolean indicating if we are on vacation--
        /// return a string in the form of "7:00" indicating when the alarm clock should ring.
        /// on weekends, the alarm should ring at "10:00", but
        /// on the weekdays, the alarm should ring at "7:00" unless we are on vacation,
        /// in which the alarm will then ring at "10:00" on the weekdays but "off" during the weekend.
        /// </summary>
        /// <param name="dayOfWeek"></param>
        /// <param name="vacation"></param>
        /// <returns>either: "7:00" or "10:00" or "off"</returns>
        public static string AlarmClock(DayOfWeek dayOfWeek, bool vacation)
        {
            //throw new NotImplementedException();

            if (vacation)
            {
                if (dayOfWeek.Equals(DayOfWeek.Sunday) || dayOfWeek.Equals(DayOfWeek.Saturday))
                {
                    return("off");
                }
                else
                {
                    return("10:00");
                }
            }
            else
            {
                if (dayOfWeek.Equals(DayOfWeek.Sunday) || dayOfWeek.Equals(DayOfWeek.Saturday))
                {
                    return("10:00");
                }
                else
                {
                    return("7:00");
                }
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            DateTime[] holidays = new DateTime[12];
            holidays[0]  = new DateTime(4, 01, 01);
            holidays[1]  = new DateTime(4, 03, 03);
            holidays[2]  = new DateTime(4, 05, 01);
            holidays[3]  = new DateTime(4, 05, 06);
            holidays[4]  = new DateTime(4, 05, 24);
            holidays[5]  = new DateTime(4, 09, 06);
            holidays[6]  = new DateTime(4, 09, 22);
            holidays[7]  = new DateTime(4, 11, 01);
            holidays[9]  = new DateTime(4, 12, 24);
            holidays[10] = new DateTime(4, 12, 25);
            holidays[11] = new DateTime(4, 12, 26);

            DateTime start = DateTime.ParseExact(Console.ReadLine(), "dd-MM-yyyy", CultureInfo.InvariantCulture);
            DateTime end   = DateTime.ParseExact(Console.ReadLine(), "dd-MM-yyyy", CultureInfo.InvariantCulture);

            int  count = 0;
            bool skip  = false;

            for (DateTime date = start; date <= end; date = date.AddDays(1))
            {
                DayOfWeek day = date.DayOfWeek;

                DateTime temp = new DateTime(4, date.Month, date.Day);

                if (!holidays.Contains(temp) && (!day.Equals(DayOfWeek.Saturday) && !day.Equals(DayOfWeek.Sunday)))
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
Beispiel #7
0
        static void Main()
        {
            string   startDate  = Console.ReadLine();
            string   endDate    = Console.ReadLine();
            DateTime startDatee = DateTime.ParseExact(startDate, "dd-MM-yyyy", CultureInfo.InvariantCulture);
            DateTime endDatee   = DateTime.ParseExact(endDate, "dd-MM-yyyy", CultureInfo.InvariantCulture);

            DateTime[] holidays = new DateTime[12];
            holidays[0]  = new DateTime(4, 01, 01);
            holidays[1]  = new DateTime(4, 03, 03);
            holidays[2]  = new DateTime(4, 05, 01);
            holidays[3]  = new DateTime(4, 05, 06);
            holidays[4]  = new DateTime(4, 05, 24);
            holidays[5]  = new DateTime(4, 09, 06);
            holidays[6]  = new DateTime(4, 09, 22);
            holidays[7]  = new DateTime(4, 11, 01);
            holidays[9]  = new DateTime(4, 12, 24);
            holidays[10] = new DateTime(4, 12, 25);
            holidays[11] = new DateTime(4, 12, 26);
            int workingDayCounter = 0;

            for (DateTime i = startDatee; i <= endDatee; i = i.AddDays(1))
            {
                DayOfWeek day = i.DayOfWeek;

                DateTime temp = new DateTime(4, i.Month, i.Day);

                if (!holidays.Contains(temp) && (!day.Equals(DayOfWeek.Saturday) && !day.Equals(DayOfWeek.Sunday)))
                {
                    workingDayCounter++;
                }
            }
            Console.WriteLine(workingDayCounter);
        }
Beispiel #8
0
        // return int of freqs enum based on time of day and bus service
        public static int GetTimeOfDay(string routeName)
        {
            // one freq case (express services)
            if (BusHelper.BusSvcs [routeName].freq.Count == 1)
            {
                return((int)Freqs.HIGH);
            }

            DateTime  now  = DateTime.Now;
            DayOfWeek day  = now.DayOfWeek;
            TimeSpan  time = now.TimeOfDay;

            // case A1/A2/D1/D2
            if (routeName[0].Equals('A') || routeName[0].Equals('D'))
            {
                if (day.Equals(DayOfWeek.Sunday) || (day.Equals(DayOfWeek.Saturday) && time > new TimeSpan(20, 0, 0)))
                {
                    return((int)Freqs.LOW);
                }

                TimeSpan[] peakStarts = { new TimeSpan(8, 0, 0), new TimeSpan(12, 0, 0), new TimeSpan(17, 0, 0) };
                TimeSpan[] peakEnds   = { new TimeSpan(10, 0, 0), new TimeSpan(14, 0, 0), new TimeSpan(20, 0, 0) };
                for (int i = 0; i < peakStarts.Length; i++)
                {
                    if (time > peakStarts [i] && time < peakEnds [i])
                    {
                        return((int)Freqs.HIGH);
                    }
                }

                return((int)Freqs.MID);
            }
            else if (routeName.Equals("BTC"))
            {
                if (day.Equals(DayOfWeek.Saturday))
                {
                    return((int)Freqs.LOW);
                }

                TimeSpan[] peakStarts = { new TimeSpan(7, 20, 0), new TimeSpan(12, 0, 0), new TimeSpan(17, 0, 0) };
                TimeSpan[] peakEnds   = { new TimeSpan(9, 0, 0), new TimeSpan(14, 0, 0), new TimeSpan(20, 0, 0) };
                for (int i = 0; i < peakStarts.Length; i++)
                {
                    if (time > peakStarts [i] && time < peakEnds [i])
                    {
                        return((int)Freqs.HIGH);
                    }
                }

                return((int)Freqs.MID);
            }
            else
            {
                // case B/C, only two freqs
                return((day.Equals(DayOfWeek.Saturday) || time > new TimeSpan(19, 0, 0)) ?
                       (int)Freqs.MID : (int)Freqs.HIGH);
            }
        }
        private bool IsTodaySundayOrMonday()
        {
            DayOfWeek numberDay = dateTimeHelper.GetDateTimeNow().DayOfWeek;

            if (numberDay.Equals(DayOfWeek.Sunday) || numberDay.Equals(DayOfWeek.Monday))
            {
                return(true);
            }
            return(false);
        }
Beispiel #10
0
        public static ServiceDayViewModel createServiceDayForHolidayAbsence(DateTime currentDate)
        {
            //Creates a day for a holiday / absence.  May not need to complete all fields
            ServiceDayViewModel retval     = new ServiceDayViewModel();
            DayOfWeek           currentDay = currentDate.DayOfWeek;

            if (currentDay.Equals(DayOfWeek.Saturday) || currentDay.Equals(DayOfWeek.Sunday))
            {
                //We don't set it for weekends
                return(null);
            }

            //Set the items which don't change by the day
            retval.DailyReport        = "";
            retval.DtReport           = currentDate;
            retval.Mileage            = 0;
            retval.OvernightAllowance = false;
            retval.PartsSuppliedToday = "";
            retval.TravelTimeFromSite = 0;
            retval.TravelTimeToSite   = 0;

            //Day always starts at 8 am.
            TimeSpan dayStartTime     = new TimeSpan(8, 0, 0);
            DateTime dayStartDateTime = currentDate.Date + dayStartTime;
            DateTime dayEndDateTime   = new DateTime();
            int      totalTimeOnsite  = 0;

            switch (currentDay)
            {
            case DayOfWeek.Monday:
            case DayOfWeek.Tuesday:
            case DayOfWeek.Wednesday:
            case DayOfWeek.Thursday:
                totalTimeOnsite = 8;
                dayEndDateTime  = dayStartDateTime.AddHours(totalTimeOnsite);
                break;

            case DayOfWeek.Friday:
                totalTimeOnsite = 6;
                dayEndDateTime  = dayStartDateTime.AddHours(totalTimeOnsite);
                break;

            default:
                throw new Exception("Unknown day: " + currentDay.ToString());
            }

            retval.TravelStartTime   = dayStartDateTime;
            retval.ArrivalOnsiteTime = dayStartDateTime;
            retval.DepartureSiteTime = dayEndDateTime;
            retval.TravelEndTime     = dayEndDateTime;
            retval.TotalOnsiteTime   = totalTimeOnsite;
            retval.TotalTravelTime   = 0;

            return(retval);
        }
 private void JudgeWeekend(DayOfWeek day)
 {
     if (day.Equals(DayOfWeek.Saturday) || day.Equals(DayOfWeek.Sunday))
     {
         popup_weekend.SetActive(true);
     }
     else
     {
         pupup_weekdays.SetActive(true);
     }
 }
 /// <summary>
 /// Given a day of the week encoded as DayOfWeek enum (i.e. named integers):
 /// Sunday=0, Monday=1, Tuesday=2, ...Saturday=6,
 /// and a boolean indicating if we are on vacation--
 /// return a string in the form of "7:00" indicating when the alarm clock should ring.
 /// on weekends, the alarm should ring at "10:00", but
 /// on the weekdays, the alarm should ring at "7:00" unless we are on vacation,
 /// in which the alarm will then ring at "10:00" on the weekdays but "off" during the weekend.
 /// </summary>
 /// <param name="dayOfWeek"></param>
 /// <param name="vacation"></param>
 /// <returns>either: "7:00" or "10:00" or "off"</returns>
 public static string AlarmClock(DayOfWeek dayOfWeek, bool vacation)
 {
     if (vacation || dayOfWeek.Equals(1 - 5))
     {
         return("10:00");
     }
     else if (vacation && dayOfWeek.Equals(0 - 6))
     {
         return("off");
     }
     return("7:00");
     //throw new NotImplementedException();
 }
 /// <summary>
 ///     Finds the total number of instances of a specific DayOfWeek in a month.
 /// </summary>
 /// <param name="dayOfWeek">The day of week.</param>
 /// <param name="year">The year.</param>
 /// <param name="month">The month.</param>
 /// <returns></returns>
 public static int TotalInstancesInMonth(
     this DayOfWeek dayOfWeek,
     int year,
     int month)
 {
     return(DateTimeExtensions.DaysOfMonth(year, month).Count(date => dayOfWeek.Equals(date.DayOfWeek)));
 }
Beispiel #14
0
        static void Main(string[] args)
        {
            DateTime startDate = DateTime.ParseExact(Console.ReadLine(), "dd-MM-yyyy", CultureInfo.InvariantCulture);
            DateTime endDate   = DateTime.ParseExact(Console.ReadLine(), "dd-MM-yyyy", CultureInfo.InvariantCulture);

            DateTime[] nonWorkingDays = new DateTime[11];
            nonWorkingDays[0]  = new DateTime(4, 01, 01);
            nonWorkingDays[1]  = new DateTime(4, 03, 03);
            nonWorkingDays[2]  = new DateTime(4, 05, 01);
            nonWorkingDays[3]  = new DateTime(4, 05, 06);
            nonWorkingDays[4]  = new DateTime(4, 05, 24);
            nonWorkingDays[5]  = new DateTime(4, 09, 06);
            nonWorkingDays[6]  = new DateTime(4, 09, 22);
            nonWorkingDays[7]  = new DateTime(4, 11, 01);
            nonWorkingDays[8]  = new DateTime(4, 12, 24);
            nonWorkingDays[9]  = new DateTime(4, 12, 25);
            nonWorkingDays[10] = new DateTime(4, 12, 26);

            int workingDayCounter = 0;

            for (DateTime currDate = startDate; currDate <= endDate; currDate = currDate.AddDays(1))
            {
                DayOfWeek currentDayOfWeek = currDate.DayOfWeek;
                DateTime  currentDate      = new DateTime(4, currDate.Month, currDate.Day);
                if (!nonWorkingDays.Contains(currentDate) && !currentDayOfWeek.Equals(DayOfWeek.Saturday) && !currentDayOfWeek.Equals(DayOfWeek.Sunday))
                {
                    workingDayCounter++;
                }
            }
            Console.WriteLine(workingDayCounter);
        }
Beispiel #15
0
        public void TryGetEnumFromEnumType(DayOfWeek expected, Enum value)
        {
            var isParsed = Enum <DayOfWeek> .TryGetEnumValue(value, out var dayOfWeek);

            Assert.True(isParsed, "Can parse");
            Assert.True(expected.Equals(dayOfWeek), "Enum-value compare");
        }
Beispiel #16
0
        /// <summary>
        ///     Finds the NTH week day of a month.
        /// </summary>
        /// <param name="dayOfWeek">The day of week.</param>
        /// <param name="year">The year.</param>
        /// <param name="month">The month.</param>
        /// <param name="n">The nth instance.</param>
        /// <remarks>Compensates for 4th and 5th DayOfWeek of Month</remarks>
        public static DateTime FindNthWeekDayOfMonth(this DayOfWeek dayOfWeek,
                                                     int year,
                                                     int month,
                                                     int n)
        {
            if (n < 1 || n > 5)
            {
                throw new ArgumentOutOfRangeException(nameof(n));
            }

            var y = 0;

            var daysOfMonth = DateTimeExtensions.DaysOfMonth(year, month);

            // compensate for "last DayOfWeek in month"
            var totalInstances = dayOfWeek.TotalInstancesInMonth(year, month);

            if (n == 5 && n > totalInstances)
            {
                n = 4;
            }

            var foundDate = daysOfMonth.Where(date => dayOfWeek.Equals(date.DayOfWeek))
                            .OrderBy(date => date)
                            .Select(x => new { n = ++y, date = x })
                            .Where(x => x.n.Equals(n))
                            .Select(x => x.date)
                            .First();            //black magic wizardry

            return(foundDate);
        }
        static void Main()
        {
            DateTime startDate = DateTime.ParseExact(Console.ReadLine(), "dd-MM-yyyy", CultureInfo.InvariantCulture);
            DateTime endDate   = DateTime.ParseExact(Console.ReadLine(), "dd-MM-yyyy", CultureInfo.InvariantCulture);

            DateTime[] holidays = new DateTime[]
            {
                new DateTime(2000, 01, 01),
                new DateTime(2000, 03, 03),
                new DateTime(2000, 05, 01),
                new DateTime(2000, 05, 06),
                new DateTime(2000, 05, 24),
                new DateTime(2000, 09, 06),
                new DateTime(2000, 09, 22),
                new DateTime(2000, 11, 01),
                new DateTime(2000, 12, 24),
                new DateTime(2000, 12, 25),
                new DateTime(2000, 12, 26)
            };

            int workingDaysCntr = 0;

            for (DateTime i = startDate; i <= endDate; i = i.AddDays(1))
            {
                DayOfWeek currentDay  = i.DayOfWeek;
                DateTime  currentDate = new DateTime(2000, i.Month, i.Day);

                if (!holidays.Contains(currentDate) && (!currentDay.Equals(DayOfWeek.Saturday) && !currentDay.Equals(DayOfWeek.Sunday)))
                {
                    workingDaysCntr++;
                }
            }

            Console.WriteLine(workingDaysCntr);
        }
Beispiel #18
0
        public void TryParse(DayOfWeek expected, string value, bool ignoreCase)
        {
            var isParsed = Enum <DayOfWeek> .TryParse(value, ignoreCase, out var dayOfWeek);

            Assert.True(isParsed, "Can parse");
            Assert.True(expected.Equals(dayOfWeek), "Enum-value compare");
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            string   startDate = Console.ReadLine();
            string   endDate   = Console.ReadLine();
            DateTime start     = DateTime.ParseExact(startDate, "dd-MM-yyyy", CultureInfo.InvariantCulture);
            DateTime end       = DateTime.ParseExact(endDate, "dd-MM-yyyy", CultureInfo.InvariantCulture);

            DateTime[] hollidays = new DateTime[11];
            hollidays[0]  = new DateTime(4, 01, 01);
            hollidays[1]  = new DateTime(4, 03, 03);
            hollidays[2]  = new DateTime(4, 05, 01);
            hollidays[3]  = new DateTime(4, 05, 06);
            hollidays[4]  = new DateTime(4, 05, 24);
            hollidays[5]  = new DateTime(4, 09, 06);
            hollidays[6]  = new DateTime(4, 09, 22);
            hollidays[7]  = new DateTime(4, 11, 01);
            hollidays[8]  = new DateTime(4, 12, 24);
            hollidays[9]  = new DateTime(4, 12, 25);
            hollidays[10] = new DateTime(4, 12, 26);

            int countWorkingDays = 0;

            for (DateTime i = start; i <= end; i = i.AddDays(1))
            {
                DayOfWeek day     = i.DayOfWeek;
                DateTime  current = new DateTime(4, i.Month, i.Day);
                if (!hollidays.Contains(current) && (!day.Equals(DayOfWeek.Saturday) && !day.Equals(DayOfWeek.Sunday)))
                {
                    countWorkingDays++;
                }
            }

            Console.WriteLine(countWorkingDays);
        }
Beispiel #20
0
 public static bool IsEndOfWeek(DayOfWeek dayOfWeek)
 {
     if (dayOfWeek.Equals(DayOfWeek.Sunday))
     {
         return(true);
     }
     return(false);
 }
Beispiel #21
0
    static void Main(string[] args)
    { //85/100
        DateTime startDate = DateTime
                             .ParseExact(Console.ReadLine(),
                                         "dd-MM-yyyy",
                                         CultureInfo
                                         .InvariantCulture);
        DateTime endDate = DateTime
                           .ParseExact(Console.ReadLine(),
                                       "dd-MM-yyyy",
                                       CultureInfo
                                       .InvariantCulture);

        DateTime[] holidays = new DateTime[]
        {
            new DateTime(0001, 01, 01),
            new DateTime(0001, 03, 03),
            new DateTime(0001, 05, 01),
            new DateTime(0001, 05, 06),
            new DateTime(0001, 05, 24),
            new DateTime(0001, 09, 06),
            new DateTime(0001, 09, 22),
            new DateTime(0001, 11, 01),
            new DateTime(0001, 12, 24),
            new DateTime(0001, 12, 25),
            new DateTime(0001, 12, 26)
        };

        int workingDays = 0;

        for (DateTime i = startDate; i <= endDate; i = i.AddDays(1))
        {
            DayOfWeek day = i.DayOfWeek;

            DateTime temp = new DateTime(0001, i.Month, i.Day);

            if (!holidays.Contains(temp) &&
                (!day.Equals(DayOfWeek.Saturday) &&
                 !day.Equals(DayOfWeek.Sunday)))
            {
                workingDays++;
            }
        }

        Console.WriteLine(workingDays);
    }
Beispiel #22
0
        public Ticket(string ticketId, string passengerId, Flight flight, double price)
        {
            this.ticketId    = ticketId;
            this.passengerId = passengerId;
            this.flight      = flight;
            this.price       = price;

            DayOfWeek dayOfWeek = flight.Date.DayOfWeek;

            if (dayOfWeek.Equals(DayOfWeek.Saturday) || dayOfWeek.Equals(DayOfWeek.Sunday))
            {
                extraTax = 0.07;
            }
            else
            {
                extraTax = 0.05;
            }
        }
Beispiel #23
0
        static void Main()
        {
            var startDateInput = Console.ReadLine()
                                 .Split('-')
                                 .Select(int.Parse)
                                 .ToArray();

            var endDateInput = Console.ReadLine()
                               .Split('-')
                               .Select(int.Parse)
                               .ToArray();

            var holidays = new DateTime[]
            {
                new DateTime(04, 01, 01),
                new DateTime(04, 03, 03),
                new DateTime(04, 05, 01),
                new DateTime(04, 05, 06),
                new DateTime(04, 05, 24),
                new DateTime(04, 09, 06),
                new DateTime(04, 09, 22),
                new DateTime(04, 11, 01),
                new DateTime(04, 12, 24),
                new DateTime(04, 12, 25),
                new DateTime(04, 12, 26),
            };

            int workingDayCounter = 0;

            DateTime startDate = new DateTime(startDateInput[2], startDateInput[1], startDateInput[0]);
            DateTime endDate   = new DateTime(endDateInput[2], endDateInput[1], endDateInput[0]);

            for (DateTime i = startDate; i <= endDate; i = i.AddDays(1))
            {
                DayOfWeek day  = i.DayOfWeek;
                DateTime  temp = new DateTime(4, i.Month, i.Day);

                if (!holidays.Contains(temp) && (!day.Equals(DayOfWeek.Saturday) && !day.Equals(DayOfWeek.Sunday)))
                {
                    workingDayCounter++;
                }
            }
            Console.WriteLine(workingDayCounter);
        }
Beispiel #24
0
    private DateTime GetLastDay(DayOfWeek dayOfWeek)
    {
        DateTime date = new DateTime(this.Year, this.Month, DateTime.DaysInMonth(this.Year, this.Month));

        while (!dayOfWeek.Equals(date.DayOfWeek))
        {
            date = new DateTime(this.Year, this.Month, date.Day - 1);
        }
        return(date);
    }
Beispiel #25
0
    private DateTime GetTeenthDay(DayOfWeek dayOfWeek)
    {
        DateTime date = new DateTime(this.Year, this.Month, 13);

        while (!dayOfWeek.Equals(date.DayOfWeek))
        {
            date = new DateTime(this.Year, this.Month, date.Day + 1);
        }
        return(date);
    }
        public static DateTime GetDateOfDayOfWeek(this DateTime dt, DayOfWeek startOfWeek)
        {
            int diff = (7 + (dt.DayOfWeek - startOfWeek)) % 7;

            if (startOfWeek.Equals(DayOfWeek.Sunday))
            {
                return(dt.Latest().AddDays(-1 * diff).Date);
            }
            return(dt.Midnight().AddDays(-1 * diff).Date);
        }
Beispiel #27
0
        /// <summary>
        /// Compares two regular hours objects for equality.
        /// </summary>
        /// <param name="RegularHours">A regular hours object to compare with.</param>
        /// <returns>True if both match; False otherwise.</returns>
        public Boolean Equals(RegularHours RegularHours)
        {
            if ((Object)RegularHours == null)
            {
                return(false);
            }

            return(DayOfWeek.Equals(RegularHours.DayOfWeek) &&
                   PeriodBegin.Equals(RegularHours.PeriodBegin) &&
                   PeriodEnd.Equals(RegularHours.PeriodEnd));
        }
Beispiel #28
0
        /// <summary>
        /// Compares two RegularHourss for equality.
        /// </summary>
        /// <param name="RegularHours">A RegularHours to compare with.</param>
        /// <returns>True if both match; False otherwise.</returns>
        public Boolean Equals(RegularHours RegularHours)
        {
            if ((Object)RegularHours == null)
            {
                return(false);
            }

            return(_Weekday.Equals(RegularHours._Weekday) &&
                   _Begin.Equals(RegularHours._Begin) &&
                   _End.Equals(RegularHours._End));
        }
Beispiel #29
0
        protected internal virtual RecurringEvents IsRecurring(
            DateTime compareTime,
            Calendar processCalendar)
        {
            if (this.Recurring != RecurringEvents.None)
            {
                switch (this.Recurring)
                {
                case RecurringEvents.DayInMonth:
                    if (processCalendar.GetDayOfMonth(compareTime).Equals(processCalendar.GetDayOfMonth(this.Date)))
                    {
                        return(this.Recurring);
                    }
                    break;

                case RecurringEvents.DayAndMonth:
                    int dayOfMonth1 = processCalendar.GetDayOfMonth(compareTime);
                    int dayOfMonth2 = processCalendar.GetDayOfMonth(this.Date);
                    int month1      = processCalendar.GetMonth(compareTime);
                    int month2      = processCalendar.GetMonth(this.Date);
                    if (dayOfMonth1.Equals(dayOfMonth2) && month1.Equals(month2))
                    {
                        return(this.Recurring);
                    }
                    break;

                case RecurringEvents.Week:
                    if (processCalendar.GetDayOfWeek(compareTime).Equals((object)processCalendar.GetDayOfWeek(this.Date)))
                    {
                        return(this.Recurring);
                    }
                    break;

                case RecurringEvents.WeekAndMonth:
                    DayOfWeek dayOfWeek1 = processCalendar.GetDayOfWeek(compareTime);
                    DayOfWeek dayOfWeek2 = processCalendar.GetDayOfWeek(this.Date);
                    int       month3     = processCalendar.GetMonth(compareTime);
                    int       month4     = processCalendar.GetMonth(this.Date);
                    if (dayOfWeek1.Equals((object)dayOfWeek2) && month3.Equals(month4))
                    {
                        return(this.Recurring);
                    }
                    break;

                case RecurringEvents.Today:
                    if (compareTime.Equals(DateTime.Today))
                    {
                        return(this.Recurring);
                    }
                    break;
                }
            }
            return(RecurringEvents.None);
        }
 public string getDia(DayOfWeek i)
 {
     if (i.Equals(DayOfWeek.Sunday))
     {
         return("Domingo");
     }
     else if (i.Equals(DayOfWeek.Monday))
     {
         return("Lunes");
     }
     else if (i.Equals(DayOfWeek.Thursday))
     {
         return("Jueves");
     }
     else if (i.Equals(DayOfWeek.Wednesday))
     {
         return("Miercoles");
     }
     else if (i.Equals(DayOfWeek.Tuesday))
     {
         return("Martes");
     }
     else if (i.Equals(DayOfWeek.Friday))
     {
         return("Viernes");
     }
     else
     {
         return("Sábado");
     }
 }
Beispiel #31
0
    public static int CalculateWorkdays(DateTime toDate, DateTime[] holidays)
    {
        // Inizializing data types
        int days;
        int workdaysCounter = 0;

        DateTime currentDate = new DateTime();

        // Getting how many days there are between today
        // and the given date
        TimeSpan span = endDay.Subtract(DateTime.Today);
        days = (int)span.TotalDays;

        DayOfWeek weekDay = new DayOfWeek();

        // Counting the workdays, excluding holidays
        for (int i = 1; i < days; i++)
        {
            currentDate = DateTime.Today.AddDays(i);
            weekDay = currentDate.DayOfWeek;

            if (weekDay.Equals(DayOfWeek.Saturday) || weekDay.Equals(DayOfWeek.Sunday))
            {
                continue;
            }

            for (int j = 0; j < holidays.Length; j++)
            {
                if (currentDate == holidays[j])
                {
                    workdaysCounter--;
                    break;
                }
            }

            workdaysCounter++;
        }

        return workdaysCounter;
    }
Beispiel #32
0
		static int GetMaxEvents(DayOfWeek d, Event.StartTimes s, bool nyeSpecial)
		{
			if (nyeSpecial)
			{
				int[] i = new int[3];
				if (d.Equals(DayOfWeek.Monday))
					i = new int[] { 5, 10, 40 };
				else if (d.Equals(DayOfWeek.Tuesday))
					i = new int[] { 20, 10, 10 };

				if (s.Equals(Event.StartTimes.Morning))
					return i[0];
				else if (s.Equals(Event.StartTimes.Daytime))
					return i[1];
				else
					return i[2];
			}
			else
			{
				int[] i = new int[3];
				if (d.Equals(DayOfWeek.Sunday))
					i = new int[] { 5, 5, 10 };
				else if (d.Equals(DayOfWeek.Monday))
					i = new int[] { 2, 2, 5 };
				else if (d.Equals(DayOfWeek.Tuesday))
					i = new int[] { 2, 2, 5 };
				else if (d.Equals(DayOfWeek.Wednesday))
					i = new int[] { 2, 2, 5 };
				else if (d.Equals(DayOfWeek.Thursday))
					i = new int[] { 2, 2, 10 };
				else if (d.Equals(DayOfWeek.Friday))
					i = new int[] { 2, 2, 20 };
				else if (d.Equals(DayOfWeek.Saturday))
					i = new int[] { 5, 5, 20 };

				if (s.Equals(Event.StartTimes.Morning))
					return i[0];
				else if (s.Equals(Event.StartTimes.Daytime))
					return i[1];
				else
					return i[2];
			}
		}