Пример #1
0
        public static HashSet <EDaysOfWeekExt> ConvertFrom(EDaysOfWeekFlags daysOfWeek)
        {
            HashSet <EDaysOfWeekExt> retVal = new HashSet <EDaysOfWeekExt>();

            foreach (EDaysOfWeekFlags d in DaysOfWeekFlags.AsSeperateValues(daysOfWeek))
            {
                retVal.Add((EDaysOfWeekExt)Enum.Parse(typeof(EDaysOfWeekExt), Enum.GetName(typeof(EDaysOfWeekFlags), d)));
            }

            return(retVal);
        }
Пример #2
0
        public DateTime GetPrevious(DateTime fromDate)
        {
            if (this.WeekCount <= 0)
            {
                throw new InvalidOperationException($"Invalid Week Count property value ({this.WeekCount})");
            }
            if (this.DaysOfWeek == EDaysOfWeekFlags.None)
            {
                throw new InvalidOperationException("No days of the week selected.");
            }

            DateTime date = fromDate;
            HashSet <EDaysOfWeekFlags> dowSet = DaysOfWeekFlags.AsSeperateValues(this.DaysOfWeek);

            // move up to the next week day that is in DaysOfWeek property and subtract (WeekCount * 7) days.
            while (!dowSet.Contains(DaysOfWeekFlags.ConvertFrom(date.DayOfWeek)))
            {
                date = date.AddDays(1);
            }
            return(date.AddDays(-(this.WeekCount * 7)).Date);
        }