ValueNextSend
を表すというプロパティがあるとします。DateTime
4/11/2011 10:30:00 AM - Monday
この場合、特定の日に毎週送信する必要があるスケジュールがあるとしましょう。その(Monday)
ため、次の週のスケジュールを把握するために、DayOfWeek
一致するまで次の日付の日ごとにチェックする必要があるという解決策になりspecific day
ました。スケジュール
4/
17 /2011 10:30:00 AM - Monday
翌日の日付の曜日名をチェックすることを克服するための他の最良の方法はありますか?
ここに私の言及したロジックがあります:
int nowYear = DateTime.Now.Year;
int nowMonth = DateTime.Now.Month;
int nowDay = DateTime.Now.Day;
int scheduleHour = this.Schedule.Time.Value.Hour;
int scheduleMinute = this.Schedule.Time.Value.Minute;
int scheduleSecond = this.Schedule.Time.Value.Second;
int scheduleDay = -1;
if(this.Schedule.Day.HasValue)
scheduleDay= this.Schedule.Day.Value;
switch (type)
{
case Schedule.ScheduleType.Weekly:
bool founded = false;
while (!founded)
{
//Check if last day of the current month
if (DateTime.DaysInMonth(nowYear, nowMonth) == nowDay)
{
//last day at this year, then move to next year
if (nowMonth == 12)
{
nowYear++;
nowMonth = 1;
nowDay = 1;
}
//its the end of a month then Move to next month
else
{
nowMonth++;
nowDay = 1;
}
}
//Get new proposed date
newNextSend = new DateTime(nowYear, nowMonth, nowDay, scheduleHour, scheduleMinute, scheduleSecond);
//Check if Next week schedule founded with specific day name
if (newNextSend.DayOfWeek ==
(DayOfWeek)Enum.Parse(typeof(DayOfWeek), Schedule.daysCalendar[scheduleDay - 1]))
{
founded = true;
}
else
nowDay++;
}
break;
}