public void ShouldReturnNextYear(Month month, DayOfTheWeek day, DayOfTheWeekIndex index, string expected) { var date = DateTime.Parse("2017-01-01"); var expectedDate = DateTime.Parse(expected); var actual = date.AddRelativeYears(1, month, day, index); Assert.Equal(expectedDate, actual); }
public void ShouldReturnNextMonth(DayOfTheWeek day, DayOfTheWeekIndex index, string from, string expected) { var date = DateTime.Parse(from); var expectedDate = DateTime.Parse(expected); var actual = date.AddRelativeMonths(1, day, index); Assert.Equal(expectedDate, actual); }
/// <summary> /// Initializes a new instance of the <see cref="TimeChangeRecurrence"/> class. /// </summary> /// <param name="dayOfTheWeekIndex">The index of the day in the month at which the time change occurs.</param> /// <param name="dayOfTheWeek">The day of the week the time change occurs.</param> /// <param name="month">The month the time change occurs.</param> public TimeChangeRecurrence( DayOfTheWeekIndex dayOfTheWeekIndex, DayOfTheWeek dayOfTheWeek, Month month) : this() { this.dayOfTheWeekIndex = dayOfTheWeekIndex; this.dayOfTheWeek = dayOfTheWeek; this.month = month; }
/// <summary> /// Initializes a new instance of the <see cref="RelativeMonthlyPattern"/> class. /// </summary> /// <param name="startDate">The date and time when the recurrence starts.</param> /// <param name="interval">The number of months between each occurrence.</param> /// <param name="dayOfTheWeek">The day of the week each occurrence happens.</param> /// <param name="dayOfTheWeekIndex">The relative position of the day within the month.</param> public RelativeMonthlyPattern( DateTime startDate, int interval, DayOfTheWeek dayOfTheWeek, DayOfTheWeekIndex dayOfTheWeekIndex) : base(startDate, interval) { this.DayOfTheWeek = dayOfTheWeek; this.DayOfTheWeekIndex = dayOfTheWeekIndex; }
/// <summary> /// Initializes a new instance of the <see cref="TimeChangeRecurrence"/> class. /// </summary> /// <param name="dayOfTheWeekIndex">The index of the day in the month at which the time change occurs.</param> /// <param name="dayOfTheWeek">The day of the week the time change occurs.</param> /// <param name="month">The month the time change occurs.</param> public TimeChangeRecurrence( DayOfTheWeekIndex dayOfTheWeekIndex, DayOfTheWeek dayOfTheWeek, Month month) : this() { this.dayOfTheWeekIndex = dayOfTheWeekIndex; this.dayOfTheWeek = dayOfTheWeek; this.month = month; }
/// <summary> /// Initializes a new instance of the <see cref="RelativeMonthlyPattern"/> class. /// </summary> /// <param name="startDate">The date and time when the recurrence starts.</param> /// <param name="interval">The number of months between each occurrence.</param> /// <param name="dayOfTheWeek">The day of the week each occurrence happens.</param> /// <param name="dayOfTheWeekIndex">The relative position of the day within the month.</param> public RelativeMonthlyPattern( DateTime startDate, int interval, DayOfTheWeek dayOfTheWeek, DayOfTheWeekIndex dayOfTheWeekIndex) : base(startDate, interval) { this.DayOfTheWeek = dayOfTheWeek; this.DayOfTheWeekIndex = dayOfTheWeekIndex; }
/// <summary> /// Initializes a new instance of the <see cref="RelativeYearlyPattern"/> class. /// </summary> /// <param name="startDate">The date and time when the recurrence starts.</param> /// <param name="month">The month of the year each occurrence happens.</param> /// <param name="dayOfTheWeek">The day of the week each occurrence happens.</param> /// <param name="dayOfTheWeekIndex">The relative position of the day within the month.</param> public RelativeYearlyPattern( DateTime startDate, Month month, DayOfTheWeek dayOfTheWeek, DayOfTheWeekIndex dayOfTheWeekIndex) : base(startDate) { this.Month = month; this.DayOfTheWeek = dayOfTheWeek; this.DayOfTheWeekIndex = dayOfTheWeekIndex; }
private static DateTime Calculate(DayOfTheWeek dayOfTheWeek, DayOfTheWeekIndex dayOfTheWeekIndex, int month, int year) { if (dayOfTheWeekIndex == DayOfTheWeekIndex.Last) { int daysInMonth = DateTime.DaysInMonth(year, month); var lastDayOfMonth = new DateTime(year, month, daysInMonth); while (!CheckDayOfWeek(lastDayOfMonth.DayOfWeek, dayOfTheWeek)) { lastDayOfMonth = lastDayOfMonth.AddDays(-1); } return(lastDayOfMonth); } else { int count = (int)dayOfTheWeekIndex; var day = new DateTime(year, month, 1); do { if (CheckDayOfWeek(day.DayOfWeek, dayOfTheWeek)) { if (count != 0) { count--; } else { return(day); } } day = day.AddDays(1); } while (true); } }
/// <summary> /// Initializes a new instance of the <see cref="RelativeYearlyPattern"/> class. /// </summary> /// <param name="startDate">The date and time when the recurrence starts.</param> /// <param name="month">The month of the year each occurrence happens.</param> /// <param name="dayOfTheWeek">The day of the week each occurrence happens.</param> /// <param name="dayOfTheWeekIndex">The relative position of the day within the month.</param> public RelativeYearlyPattern( DateTime startDate, Month month, DayOfTheWeek dayOfTheWeek, DayOfTheWeekIndex dayOfTheWeekIndex) : base(startDate) { this.Month = month; this.DayOfTheWeek = dayOfTheWeek; this.DayOfTheWeekIndex = dayOfTheWeekIndex; }
/// <summary> /// Initializes a new instance of the <see cref="RelativeMonthlyPattern"/> class. /// </summary> /// <param name="startDate">The date and time when the recurrence starts.</param> /// <param name="interval">The number of months between each occurrence.</param> /// <param name="dayOfTheWeek">The day of the week each occurrence happens.</param> /// <param name="dayOfTheWeekIndex">The relative position of the day within the month.</param> RelativeMonthlyPattern( DateTime startDate, int interval, DayOfTheWeek dayOfTheWeek, DayOfTheWeekIndex dayOfTheWeekIndex) : super(startDate, interval)
/// <summary> /// Returns a new <see cref="System.DateTime"/> that adds the relative number of years to the value of this instance. /// </summary> /// <param name="datetime">The datetime.</param> /// <param name="value">The value.</param> /// <param name="month">The month.</param> /// <param name="dayOfTheWeek">The day of the week.</param> /// <param name="dayOfTheWeekIndex">Index of the day of the week.</param> public static DateTime AddRelativeYears(this DateTime datetime, int value, Month month, DayOfTheWeek dayOfTheWeek, DayOfTheWeekIndex dayOfTheWeekIndex) { return(Calculate(dayOfTheWeek, dayOfTheWeekIndex, (int)month, datetime.Year + value).Add(datetime.TimeOfDay)); }
/// <summary> /// Returns a new <see cref="System.DateTime"/> that adds the relative number of months to the value of this instance. /// </summary> /// <param name="datetime">The datetime.</param> /// <param name="value">The value.</param> /// <param name="dayOfTheWeek">The day of the week.</param> /// <param name="dayOfTheWeekIndex">Index of the day of the week.</param> public static DateTime AddRelativeMonths(this DateTime datetime, int value, DayOfTheWeek dayOfTheWeek, DayOfTheWeekIndex dayOfTheWeekIndex) { var v = datetime.AddMonths(value); return(Calculate(dayOfTheWeek, dayOfTheWeekIndex, v.Month, v.Year).Add(datetime.TimeOfDay)); }
/// <summary> /// Initializes a new instance of the <see cref="RelativeYearlyPattern"/> class. /// </summary> /// <param name="startDate">The date and time when the recurrence starts.</param> /// <param name="month">The month of the year each occurrence happens.</param> /// <param name="dayOfTheWeek">The day of the week each occurrence happens.</param> /// <param name="dayOfTheWeekIndex">The relative position of the day within the month.</param> RelativeYearlyPattern( DateTime startDate, Month month, DayOfTheWeek dayOfTheWeek, DayOfTheWeekIndex dayOfTheWeekIndex) : super(startDate)