public virtual DateTime GetToDate(DateTime dt, System.Globalization.Calendar calendar)
{
if (this.Order == 1 && this.FromMonth > this.ToMonth)
{
if (calendar.GetMonth(dt) == 12)
{
//در اولین بازه محدوده، ماه شروع در سال قبل قرار گرفته
dt = calendar.AddYears(dt, 1);
}
}
if (this.Order == 12 && this.FromMonth > this.ToMonth)
{
if (calendar.GetMonth(dt) == 12)
{
//در آخرین بازه محدوده، ماه پایان در سال بعد قرار گرفته
dt = calendar.AddYears(dt, 1);
}
}
else if (this.Order == 0 && this.FromMonth >= this.ToMonth)
{
//بازه سالانه است و پایان در سال بعد قرار گرفته
dt = calendar.AddYears(dt, 1);
}
if (calendar is PersianCalendar)
{
if (calendar.IsLeapYear(calendar.GetYear(dt)) && this.ToMonth == 12 && this.ToDay == 29)
{
return(calendar.ToDateTime(calendar.GetYear(dt), this.ToMonth, 30, 0, 0, 0, 0));
}
else
{
return(calendar.ToDateTime(calendar.GetYear(dt), this.ToMonth, this.ToDay, 0, 0, 0, 0));
}
}
else
{
if (calendar.IsLeapYear(dt.Year) && this.ToMonth == 2 && this.ToDay == 28)
{
//اگر سال کبسه بود و برای ماه فوریه روز 28 انتخاب شده بود
//به صورت خودکار با روز 29 جایگزین می شود
return(calendar.ToDateTime(dt.Year, this.ToMonth, 29, 0, 0, 0, 0));
}
else
{
return(calendar.ToDateTime(dt.Year, this.ToMonth, this.ToDay, 0, 0, 0, 0));
}
}
}