internal static IEnumerable <DateTime> DatesInPosition(int year, int month, WeekOfMonthPosition position) { var day = default(int); var maxDay = default(int); if (position != WeekOfMonthPosition.Last) { day = 1 + 7 * FlagsEnum.PowerOfTwoExponent(position); maxDay = day + 6; } else { maxDay = DateTime.DaysInMonth(year, month); day = maxDay - 6; } while (day <= maxDay) { yield return(new DateTime(year, month, day, 0, 0, 0, DateTimeKind.Local)); day += 1; } }
/// <summary> /// Initializes a new instance of the <see cref="RecurrentWeekDaysOfMonth"/> struct. /// </summary> /// <param name="position">The position of the <paramref name="weekDays"/> in month.</param> /// <param name="weekDays">The recurrent week days (ex: every <see cref="RecurrentWeekDays.WeekEnd"/>).</param> /// <param name="anyWeekDays">If set to <c>true</c> any <paramref name="weekDays"/> is considered when determining the next occurence; otherwise, all the <paramref name="weekDays"/> are considered.</param> /// <remarks> /// When combining any <paramref name="weekDays"/> in the <see cref="WeekOfMonthPosition.Last"/> position, /// the latest date and time matching the specified <see cref="_weekDays"/> is considered. /// </remarks> public RecurrentWeekDaysOfMonth(WeekOfMonthPosition position, RecurrentWeekDays weekDays, bool anyWeekDays) { _position = position; _weekDays = weekDays; _anyWeekDays = anyWeekDays; }
/// <summary> /// Initializes a new instance of the <see cref="RecurrentWeekDaysOfMonth"/> struct /// where all <paramref name="weekDays"/> are considered when determining the next occurence. /// </summary> /// <param name="position">The position of the <paramref name="weekDays"/> in month.</param> /// <param name="weekDays">The recurrent week days (ex: every <see cref="RecurrentWeekDays.WeekEnd"/>).</param> public RecurrentWeekDaysOfMonth(WeekOfMonthPosition position, RecurrentWeekDays weekDays) : this(position, weekDays, false) { }