internal void UpdateDecadeMode() { DateTime selectedYear; if (Owner != null) { selectedYear = Owner.DisplayYear; } else { selectedYear = DateTime.Today; } DateTime decade = GetDecadeForDecadeMode(selectedYear); DateTime decadeEnd = _calendar.AddYears(decade, 9); SetDecadeModeHeaderButton(decade); SetDecadeModePreviousButton(decade); SetDecadeModeNextButton(decadeEnd); if (_yearView != null) { SetYearButtons(decade, decadeEnd); } }
public static DateTime?AddYears(DateTime time, int years) { try { return(cal.AddYears(time, years)); } catch (System.ArgumentException) { return(null); } }
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)); } } }
public virtual DateTime GetFromDate(DateTime dt, System.Globalization.Calendar calendar) { if (this.Order == 1 && this.FromMonth > this.ToMonth) { if (calendar.GetMonth(dt) == 1) { //در اولین بازه محدوده، ماه شروع در سال قبل قرار گرفته dt = calendar.AddYears(dt, -1); } } else if (this.Order == 0 && this.FromMonth >= this.ToMonth) { //بازه سالانه است و شروع در سال قبل قرار گرفته dt = calendar.AddYears(dt, -1); } return(calendar.ToDateTime(calendar.GetYear(dt), this.FromMonth, this.FromDay, 0, 0, 0, 0)); }
public static DateTime?AddYears(DateTime time, int years) { try { return(Cal.AddYears(time, years)); } catch (ArgumentException) { return(new DateTime?()); } }
private static IEnumerable<DateTime> GetOccurrences(DateInterval interval, DatePeriod period, Calendar calendar, DateTime start, DateTime end, bool skipWeekends = true) { var difference = DateSpan.GetDifference(interval, start, end)/period.Quantifier; if (start.Kind == DateTimeKind.Utc) { start = start.ToLocalTime(); } for (var i = 0; i < difference; i++) { switch (period.Frequency) { case DatePeriodFrequency.Seconds: var seconds = calendar.AddSeconds(start, period.Quantifier * i); yield return DeferOccurrenceFallingOnWeekend(calendar, seconds, skipWeekends); break; case DatePeriodFrequency.Minutes: var minutes = calendar.AddMinutes(start, period.Quantifier * i); yield return DeferOccurrenceFallingOnWeekend(calendar, minutes, skipWeekends); break; case DatePeriodFrequency.Hours: var hours = calendar.AddHours(start, period.Quantifier * i); yield return DeferOccurrenceFallingOnWeekend(calendar, hours, skipWeekends); break; case DatePeriodFrequency.Days: var days = calendar.AddDays(start, period.Quantifier*i); yield return DeferOccurrenceFallingOnWeekend(calendar, days, skipWeekends); break; case DatePeriodFrequency.Weeks: var weeks = calendar.AddWeeks(start, period.Quantifier*i); yield return DeferOccurrenceFallingOnWeekend(calendar, weeks, skipWeekends); break; case DatePeriodFrequency.Months: var months = calendar.AddMonths(start, period.Quantifier*i); yield return DeferOccurrenceFallingOnWeekend(calendar, months, skipWeekends); break; case DatePeriodFrequency.Years: var years = calendar.AddYears(start, period.Quantifier*i); yield return DeferOccurrenceFallingOnWeekend(calendar, years, skipWeekends); break; default: throw new ArgumentException("Frequency"); } } }
public static DateTime EndOfYear( this DateTime date, Calendar calendar ) { Arg.NotNull( calendar, nameof( calendar ) ); Contract.Ensures( calendar.GetYear( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetYear( date ) ) ); return calendar.AddYears( date.StartOfYear( calendar ), 1 ).AddTicks( -1L ); }