Пример #1
0
        private bool IsWeekend(DateTime dateReceived)
        {
            if (!_cfg.AutoRespondWeekendConstraintEnabled)
            {
                return(false);
            }
            var timeReceived = dateReceived.TimeOfDay;
            var w            = new WeekendMarker((DayOfWeek)Enum.Parse(typeof(DayOfWeek), _cfg.AutoRespondWeekendDayBegin),
                                                 (DayOfWeek)Enum.Parse(typeof(DayOfWeek), _cfg.AutoRespondWeekendDayEnd));

            if ((w.IsWeekendBegin(dateReceived.DayOfWeek) && timeReceived >= new TimeSpan(_cfg.AutoRespondWeekendHourBegin, 0, 0)) ||
                w.IsWeekendMiddle(dateReceived.DayOfWeek) ||
                (w.IsWeekendEnd(dateReceived.DayOfWeek) && timeReceived <= new TimeSpan(_cfg.AutoRespondWeekendHourEnd, 0, 0)))
            {
                return(true);
            }

            return(false);
        }
Пример #2
0
        public void TestWeekend()
        {
            Console.WriteLine(_cfg.AutoRespondNightConstraintEnabled);
            var w = new WeekendMarker((DayOfWeek)Enum.Parse(typeof(DayOfWeek), _cfg.AutoRespondWeekendDayBegin), (DayOfWeek)Enum.Parse(typeof(DayOfWeek), _cfg.AutoRespondWeekendDayEnd));
            //var dateReceived = (new DateTime(2013, 8, 27, 21, 58, 00)).ToUniversalTime(); //tuesday
            //var dateReceived = (new DateTime(2013, 9, 13, 21, 58, 00)).ToUniversalTime(); // friday night
            //var dateReceived = (new DateTime(2013, 9, 14, 11, 58, 00)).ToUniversalTime(); // suturday evening
            //var dateReceived = (new DateTime(2013, 9, 15, 5, 00, 00)).ToUniversalTime(); // sunday morning
            var dateReceived = (new DateTime(2013, 9, 15, 22, 00, 00)).ToUniversalTime();             // sunday night
            var timeReceived = dateReceived.TimeOfDay;

            if ((w.IsWeekendBegin(dateReceived.DayOfWeek) && timeReceived >= new TimeSpan(_cfg.AutoRespondWeekendHourBegin, 0, 0)) ||
                w.IsWeekendMiddle(dateReceived.DayOfWeek) ||
                (w.IsWeekendEnd(dateReceived.DayOfWeek) && timeReceived <= new TimeSpan(_cfg.AutoRespondWeekendHourEnd, 0, 0)))
            {
                Console.WriteLine("weekend");
                return;
            }

            Console.WriteLine("not weekend");
        }