Skip to content

Commit

Permalink
Fixing next patching attempt date
Browse files Browse the repository at this point in the history
  • Loading branch information
Adib Alwani committed Apr 28, 2020
1 parent 29c0242 commit 4441f7a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ class ServiceSettings

public DayOfWeek DayOfWeek { get; private set; }

public int WeekOfMonth { get; private set; }

public TimeSpan Time { get; private set; }

public DateTime Date { get; private set; }

public bool IsLastDayOfMonth { get; private set; }
Expand Down Expand Up @@ -169,18 +173,14 @@ private void ParseWUFrequency()
throw new ArgumentException("Illegal WUFrequency Parameter : " + WUFrequency);
}

var weekOfMonth = (int)Convert.ChangeType(arr[1], typeof(int));
var dayOfWeek = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), arr[2]);
this.WeekOfMonth = (int)Convert.ChangeType(arr[1], typeof(int));
this.DayOfWeek = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), arr[2]);
this.Time = TimeSpan.Parse(arr[3]);

var firstDayOfMonth = new DateTime(currentDateTime.Year, currentDateTime.Month, day: 1);
var firstWeekOfMonth = firstDayOfMonth.AddDays((dayOfWeek + 7 - firstDayOfMonth.DayOfWeek) % 7);
var daysToAdd = 7 * (weekOfMonth - 1);
if ((firstWeekOfMonth.Day + daysToAdd) > MaxSupportedDayOfMonth)
if (this.WeekOfMonth < 1 || this.WeekOfMonth > 4)
{
throw new ArgumentException("Illegal WUFrequency Parameter : " + WUFrequency + ". The day of month should be between 1 to 28.");
throw new ArgumentException("Illegal WUFrequency Parameter : " + WUFrequency + ". The WeekOfMonth should be between 1 to 4.");
}
this.Date = firstWeekOfMonth.AddDays(daysToAdd);
this.Date = this.Date.Date + TimeSpan.Parse(arr[3]);
break;

case Frequency.Weekly:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,13 @@ private DateTime GetNextSchedulingTime()

case Frequency.MonthlyByWeekAndDay:
{
var next = new DateTime(currentTime.Year, currentTime.Month, settingsDateTime.Day,
settingsDateTime.Hour, settingsDateTime.Minute, settingsDateTime.Second);
var next = this.GetNextDateTimeForMonthlyByWeekAndDayFrequency(currentTime, settings);

if (DateTime.Compare(next, currentTime) < 0)
{
next = next.AddMonths(1);
next = this.GetNextDateTimeForMonthlyByWeekAndDayFrequency(currentTime.AddMonths(1), settings);
}

return next;
}

Expand Down Expand Up @@ -695,6 +696,17 @@ private DateTime GetNextSchedulingTime()
}
}

private DateTime GetNextDateTimeForMonthlyByWeekAndDayFrequency(DateTime currentTime, ServiceSettings settings)
{
var firstDayOfMonth = new DateTime(currentTime.Year, currentTime.Month, day: 1);
var firstWeekOfMonth = firstDayOfMonth.AddDays((settings.DayOfWeek + 7 - firstDayOfMonth.DayOfWeek) % 7);
var daysToAdd = 7 * (settings.WeekOfMonth - 1);
var dayOfMonth = firstWeekOfMonth.AddDays(daysToAdd);
var dayOfMonthWithTime = dayOfMonth + settings.Time;

return dayOfMonthWithTime;
}

class CheckpointFileData
{
public DateTime schedulingDateTime = default(DateTime);
Expand Down

0 comments on commit 4441f7a

Please sign in to comment.