AddMonths() public abstract method

public abstract AddMonths ( DateTime time, int months ) : DateTime
time DateTime
months int
return DateTime
コード例 #1
0
ファイル: EventCalendar.cs プロジェクト: zahedbri/mojoportal
        //Creates a title block. No customization is offered, if that's needed then specify the header template.
        Control CreateStaticTitle(DateTime visibleDate, System.Globalization.Calendar threadCalendar)
        {
            //Create a new table for the header controls

            Table titleTable = new Table();

            titleTable.GridLines   = GridLines.None;
            titleTable.Width       = Unit.Percentage(100);
            titleTable.CellSpacing = 0;

            TableRow titleTableRow = new TableRow();

            titleTable.Rows.Add(titleTableRow);

            TableCell PrevCell = new TableCell();

            titleTableRow.Cells.Add(PrevCell);
            PrevCell.ApplyStyle(nextPrevStyle);
            Button PrevBtn = new Button();

            PrevBtn.CssClass    = "buttonlink";
            PrevBtn.Text        = "< " + threadCalendar.AddMonths(visibleDate, -1).ToString("MMMM");
            PrevBtn.CommandName = COMMAND_PREVMONTH;
            PrevCell.Controls.Add(PrevBtn);

            TableCell MonthCell = new TableCell();

            titleTableRow.Cells.Add(MonthCell);
            MonthCell.ApplyStyle(titleStyle);
            MonthCell.Text = visibleDate.ToString("MMMM yyyy");

            TableCell NextCell = new TableCell();

            titleTableRow.Cells.Add(NextCell);
            NextCell.ApplyStyle(nextPrevStyle);
            Button NextBtn = new Button();

            NextBtn.CssClass    = "buttonlink";
            NextBtn.Text        = threadCalendar.AddMonths(visibleDate, +1).ToString("MMMM") + " >";
            NextBtn.CommandName = COMMAND_NEXTMONTH;
            NextCell.Controls.Add(NextBtn);

            return(titleTable);
        }
コード例 #2
0
        private void MonthListEventHandler(Object source, ListCommandEventArgs e)
        {
            _threadCalendar = DateTimeFormatInfo.CurrentInfo.Calendar;

            if (e.ListItem.Index == _monthsToDisplay)
            {
                // Next was selected
                Control.VisibleDate = _threadCalendar.AddMonths(
                    Control.VisibleDate, _monthsToDisplay);
                SecondaryUIMode = ChooseMonth;
            }
            else if (e.ListItem.Index == _monthsToDisplay + 1)
            {
                // Prev was selected
                Control.VisibleDate = _threadCalendar.AddMonths(
                    Control.VisibleDate, -_monthsToDisplay);
                SecondaryUIMode = ChooseMonth;
            }
            else
            {
                // A month was selected
                Control.VisibleDate = _threadCalendar.AddMonths(
                    Control.VisibleDate,
                    e.ListItem.Index);

                if (_chooseOption == MonthOption)
                {
                    // Add the whole month to the date list
                    DateTime beginDate = EffectiveVisibleDate(Control.VisibleDate);
                    Control.VisibleDate = beginDate;

                    DateTime endDate = _threadCalendar.AddMonths(beginDate, 1);
                    endDate = _threadCalendar.AddDays(endDate, -1);

                    SelectRange(beginDate, endDate);
                    HandlePostBackEvent(Done.ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    SecondaryUIMode = ChooseWeek;
                }
            }
        }
コード例 #3
0
 public static DateTime?AddMonths(DateTime time, int months)
 {
     try
     {
         return(cal.AddMonths(time, months));
     }
     catch (System.ArgumentException)
     {
         return(null);
     }
 }
コード例 #4
0
 public static DateTime?AddMonths(DateTime time, int months)
 {
     try
     {
         return(Cal.AddMonths(time, months));
     }
     catch (ArgumentException)
     {
         return(new DateTime?());
     }
 }
コード例 #5
0
ファイル: CalendarItem.cs プロジェクト: Deadpikle/Avalonia
 private void SetMonthModeNextButton(DateTime firstDayOfMonth)
 {
     if (Owner != null && NextButton != null)
     {
         // DisplayDate is equal to DateTime.MaxValue
         if (DateTimeHelper.CompareYearMonth(firstDayOfMonth, DateTime.MaxValue) == 0)
         {
             NextButton.IsEnabled = false;
         }
         else
         {
             // Since we are sure DisplayDate is not equal to
             // DateTime.MaxValue, it is safe to use AddMonths
             DateTime firstDayOfNextMonth = _calendar.AddMonths(firstDayOfMonth, 1);
             NextButton.IsEnabled = (DateTimeHelper.CompareDays(Owner.DisplayDateRangeEnd, firstDayOfNextMonth) > -1);
         }
     }
 }
コード例 #6
0
        private void SetMonthModeNextButton()
        {
            if (this.Owner != null && _nextButton != null)
            {
                DateTime firstDayOfMonth = DateTimeHelper.DiscardDayTime(DisplayDate);

                // DisplayDate is equal to DateTime.MaxValue
                if (DateTimeHelper.CompareYearMonth(firstDayOfMonth, DateTime.MaxValue) == 0)
                {
                    _nextButton.IsEnabled = false;
                }
                else
                {
                    // Since we are sure DisplayDate is not equal to DateTime.MaxValue,
                    // it is safe to use AddMonths
                    DateTime firstDayOfNextMonth = _calendar.AddMonths(firstDayOfMonth, 1);
                    _nextButton.IsEnabled = (DateTimeHelper.CompareDays(this.Owner.DisplayDateEndInternal, firstDayOfNextMonth) > -1);
                }
            }
        }
コード例 #7
0
        private void MonthListEventHandler(Object source, ListCommandEventArgs e)
        {
            _threadCalendar = DateTimeFormatInfo.CurrentInfo.Calendar;

            if (e.ListItem.Index == _monthsToDisplay)
            {
                // Next was selected
                Control.VisibleDate = _threadCalendar.AddMonths(
                                        Control.VisibleDate, _monthsToDisplay);
                SecondaryUIMode = ChooseMonth;
            }
            else if (e.ListItem.Index == _monthsToDisplay + 1)
            {
                // Prev was selected
                Control.VisibleDate = _threadCalendar.AddMonths(
                                        Control.VisibleDate, -_monthsToDisplay);
                SecondaryUIMode = ChooseMonth;
            }
            else
            {
                // A month was selected
                Control.VisibleDate = _threadCalendar.AddMonths(
                                        Control.VisibleDate,
                                        e.ListItem.Index);

                if (_chooseOption == MonthOption)
                {
                    // Add the whole month to the date list
                    DateTime beginDate = EffectiveVisibleDate(Control.VisibleDate);
                    Control.VisibleDate = beginDate;

                    DateTime endDate = _threadCalendar.AddMonths(beginDate, 1);
                    endDate = _threadCalendar.AddDays(endDate, -1);

                    SelectRange(beginDate, endDate);
                    HandlePostBackEvent(Done.ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    SecondaryUIMode = ChooseWeek;
                }
            }
        }
コード例 #8
0
        /// <include file='doc\ChtmlCalendarAdapter.uex' path='docs/doc[@for="ChtmlCalendarAdapter.Render"]/*' />
        public override void Render(HtmlMobileTextWriter writer)
        {
            ArrayList arr;
            DateTime tempDate;
            DateTimeFormatInfo currentDateTimeInfo = DateTimeFormatInfo.CurrentInfo;
            String abbreviatedMonthDayPattern = AbbreviateMonthPattern(currentDateTimeInfo.MonthDayPattern);
            _threadCalendar = currentDateTimeInfo.Calendar;
            bool breakAfter = false;

            writer.EnterStyle(Style);

            Debug.Assert(NotSecondaryUI == NotSecondaryUIInit);
            switch (SecondaryUIMode)
            {
                case FirstPrompt:
                    String promptText = Control.CalendarEntryText;
                    if (String.IsNullOrEmpty(promptText))
                    {
                        promptText = SR.GetString(SR.CalendarAdapterFirstPrompt);
                    }

                    // Link to input option selection screen
                    RenderPostBackEventAsAnchor(writer,
                                                OptionPrompt.ToString(CultureInfo.InvariantCulture),
                                                promptText);

                    // We should honor BreakAfter property here as the first
                    // UI is shown with other controls on the same form.
                    // For other secondary UI, it is not necessary.
                    if (Control.BreakAfter)
                    {
                        breakAfter = true;
                    }
                    break;

                // Render the first secondary page that provides differnt
                // options to select a date.
                case OptionPrompt:
                    writer.Write(SR.GetString(SR.CalendarAdapterOptionPrompt));
                    writer.WriteBreak();

                    arr = new ArrayList();

                    // Option to select the default date
                    arr.Add(Control.VisibleDate.ToString(
                        currentDateTimeInfo.ShortDatePattern, CultureInfo.CurrentCulture));

                    // Option to another page that can enter a date by typing
                    arr.Add(SR.GetString(SR.CalendarAdapterOptionType));

                    // Options to a set of pages for selecting a date, a week
                    // or a month by picking month/year, week and day
                    // accordingly.  Available options are determined by
                    // SelectionMode.
                    arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseDate));

                    if (Control.SelectionMode == CalendarSelectionMode.DayWeek ||
                        Control.SelectionMode == CalendarSelectionMode.DayWeekMonth)
                    {
                        arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseWeek));

                        if (Control.SelectionMode == CalendarSelectionMode.DayWeekMonth)
                        {
                            arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseMonth));
                        }
                    }

                    DataBindAndRender(writer, _optionList, arr);
                    break;

                // Render a title and textbox to capture a date entered by user
                case TypeDate:
                    if (_textBoxErrorMessage != null)
                    {
                        writer.Write(_textBoxErrorMessage);
                        writer.WriteBreak();
                    }

                    if (_selectList.Visible)
                    {
                        writer.Write(SR.GetString(SR.CalendarAdapterOptionEra));
                        writer.WriteBreak();
                        _selectList.RenderControl(writer);
                    }

                    String numericDateFormat = GetNumericDateFormat();

                    writer.Write(SR.GetString(SR.CalendarAdapterOptionType));
                    writer.Write(":");
                    writer.WriteBreak();
                    writer.Write("(");
                    writer.Write(numericDateFormat.ToUpper(CultureInfo.InvariantCulture));
                    writer.Write(")");

                    if (!_selectList.Visible)
                    {
                        writer.Write(GetEra(Control.VisibleDate));
                    }
                    writer.WriteBreak();

                    _textBox.Numeric = true;
                    _textBox.Size = numericDateFormat.Length;
                    _textBox.MaxLength = numericDateFormat.Length;
                    _textBox.Text = Control.VisibleDate.ToString(numericDateFormat, CultureInfo.InvariantCulture);
                    _textBox.Visible = true;
                    _textBox.RenderControl(writer);

                    // Command button for sending the textbox value back to the server
                    _command.Text = GetDefaultLabel(OKLabel);
                    _command.Visible = true;
                    _command.RenderControl(writer);

                    break;

                // Render a paged list for choosing a month
                case ChooseMonth:
                    writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseMonth));
                    writer.Write(":");
                    writer.WriteBreak();

                    tempDate = Control.VisibleDate;

                    String abbreviatedYearMonthPattern = AbbreviateMonthPattern(currentDateTimeInfo.YearMonthPattern);

                    // This is to be consistent with ASP.NET Calendar control
                    // on handling YearMonthPattern:
                    // Some cultures have a comma in their YearMonthPattern,
                    // which does not look right in a calendar.  Here we
                    // strip the comma off.
                    int indexComma = abbreviatedYearMonthPattern.IndexOf(',');
                    if (indexComma >= 0)
                    {
                        abbreviatedYearMonthPattern =
                            abbreviatedYearMonthPattern.Remove(indexComma, 1);
                    }

                    arr = new ArrayList();
                    for (int i = 0; i < _monthsToDisplay; i++)
                    {
                        arr.Add(tempDate.ToString(abbreviatedYearMonthPattern, CultureInfo.CurrentCulture));
                        tempDate = _threadCalendar.AddMonths(tempDate, 1);
                    }
                    arr.Add(GetDefaultLabel(NextLabel));
                    arr.Add(GetDefaultLabel(PreviousLabel));

                    DataBindAndRender(writer, _monthList, arr);
                    break;

                // Based on the month selected in case ChooseMonth above, render a list of
                // availabe weeks of the month.
                case ChooseWeek:
                    String monthFormat = (GetNumericDateFormat()[0] == 'y') ? "yyyy/M" : "M/yyyy";
                    writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseWeek));
                    writer.Write(" (");
                    writer.Write(Control.VisibleDate.ToString(monthFormat, CultureInfo.CurrentCulture));
                    writer.Write("):");
                    writer.WriteBreak();

                    // List weeks of days of the selected month.  May include
                    // days from the previous and the next month to fill out
                    // all six week choices.  This is consistent with the
                    // ASP.NET Calendar control.

                    // Note that the event handling code of this list control
                    // should be implemented according to the index content
                    // generated here.

                    tempDate = FirstCalendarDay(Control.VisibleDate);

                    arr = new ArrayList();
                    String weekDisplay;
                    for (int i = 0; i < 6; i++)
                    {
                        weekDisplay = tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture);
                        weekDisplay += DaySeparator;
                        tempDate = _threadCalendar.AddDays(tempDate, 6);
                        weekDisplay += tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture);
                        arr.Add(weekDisplay);
                        tempDate = _threadCalendar.AddDays(tempDate, 1);
                    }

                    DataBindAndRender(writer, _weekList, arr);
                    break;

                // Based on the month and week selected in case ChooseMonth and ChooseWeek above,
                // render a list of the dates in the week.
                case ChooseDay:
                    writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseDate));
                    writer.Write(":");
                    writer.WriteBreak();

                    tempDate = Control.VisibleDate;

                    arr = new ArrayList();
                    String date;
                    String dayName;
                    StringBuilder dayDisplay = new StringBuilder();
                    bool dayNameFirst = (GetNumericDateFormat()[0] != 'y');

                    for (int i = 0; i < 7; i++)
                    {
                        date = tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture);

                        if (Control.ShowDayHeader)
                        {
                            // Use the short format for displaying day name
                            dayName = GetAbbreviatedDayName(tempDate);
                            dayDisplay.Length = 0;

                            if (dayNameFirst)
                            {
                                dayDisplay.Append(dayName);
                                dayDisplay.Append(Space);
                                dayDisplay.Append(date);
                            }
                            else
                            {
                                dayDisplay.Append(date);
                                dayDisplay.Append(Space);
                                dayDisplay.Append(dayName);
                            }
                            arr.Add(dayDisplay.ToString());
                        }
                        else
                        {
                            arr.Add(date);
                        }
                        tempDate = _threadCalendar.AddDays(tempDate, 1);
                    }

                    DataBindAndRender(writer, _dayList, arr);
                                        break;

                default:
                    Debug.Assert(false, "Unexpected Secondary UI Mode");
                                        break;
            }

            writer.ExitStyle(Style, breakAfter);
        }
コード例 #9
0
        /// <include file='doc\ChtmlCalendarAdapter.uex' path='docs/doc[@for="ChtmlCalendarAdapter.Render"]/*' />
        public override void Render(HtmlMobileTextWriter writer)
        {
            ArrayList          arr;
            DateTime           tempDate;
            DateTimeFormatInfo currentDateTimeInfo        = DateTimeFormatInfo.CurrentInfo;
            String             abbreviatedMonthDayPattern = AbbreviateMonthPattern(currentDateTimeInfo.MonthDayPattern);

            _threadCalendar = currentDateTimeInfo.Calendar;
            bool breakAfter = false;

            writer.EnterStyle(Style);

            Debug.Assert(NotSecondaryUI == NotSecondaryUIInit);
            switch (SecondaryUIMode)
            {
            case FirstPrompt:
                String promptText = Control.CalendarEntryText;
                if (String.IsNullOrEmpty(promptText))
                {
                    promptText = SR.GetString(SR.CalendarAdapterFirstPrompt);
                }

                // Link to input option selection screen
                RenderPostBackEventAsAnchor(writer,
                                            OptionPrompt.ToString(CultureInfo.InvariantCulture),
                                            promptText);

                // We should honor BreakAfter property here as the first
                // UI is shown with other controls on the same form.
                // For other secondary UI, it is not necessary.
                if (Control.BreakAfter)
                {
                    breakAfter = true;
                }
                break;

            // Render the first secondary page that provides differnt
            // options to select a date.
            case OptionPrompt:
                writer.Write(SR.GetString(SR.CalendarAdapterOptionPrompt));
                writer.WriteBreak();

                arr = new ArrayList();

                // Option to select the default date
                arr.Add(Control.VisibleDate.ToString(
                            currentDateTimeInfo.ShortDatePattern, CultureInfo.CurrentCulture));

                // Option to another page that can enter a date by typing
                arr.Add(SR.GetString(SR.CalendarAdapterOptionType));

                // Options to a set of pages for selecting a date, a week
                // or a month by picking month/year, week and day
                // accordingly.  Available options are determined by
                // SelectionMode.
                arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseDate));

                if (Control.SelectionMode == CalendarSelectionMode.DayWeek ||
                    Control.SelectionMode == CalendarSelectionMode.DayWeekMonth)
                {
                    arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseWeek));

                    if (Control.SelectionMode == CalendarSelectionMode.DayWeekMonth)
                    {
                        arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseMonth));
                    }
                }

                DataBindAndRender(writer, _optionList, arr);
                break;

            // Render a title and textbox to capture a date entered by user
            case TypeDate:
                if (_textBoxErrorMessage != null)
                {
                    writer.Write(_textBoxErrorMessage);
                    writer.WriteBreak();
                }

                if (_selectList.Visible)
                {
                    writer.Write(SR.GetString(SR.CalendarAdapterOptionEra));
                    writer.WriteBreak();
                    _selectList.RenderControl(writer);
                }

                String numericDateFormat = GetNumericDateFormat();

                writer.Write(SR.GetString(SR.CalendarAdapterOptionType));
                writer.Write(":");
                writer.WriteBreak();
                writer.Write("(");
                writer.Write(numericDateFormat.ToUpper(CultureInfo.InvariantCulture));
                writer.Write(")");

                if (!_selectList.Visible)
                {
                    writer.Write(GetEra(Control.VisibleDate));
                }
                writer.WriteBreak();

                _textBox.Numeric   = true;
                _textBox.Size      = numericDateFormat.Length;
                _textBox.MaxLength = numericDateFormat.Length;
                _textBox.Text      = Control.VisibleDate.ToString(numericDateFormat, CultureInfo.InvariantCulture);
                _textBox.Visible   = true;
                _textBox.RenderControl(writer);

                // Command button for sending the textbox value back to the server
                _command.Text    = GetDefaultLabel(OKLabel);
                _command.Visible = true;
                _command.RenderControl(writer);

                break;

            // Render a paged list for choosing a month
            case ChooseMonth:
                writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseMonth));
                writer.Write(":");
                writer.WriteBreak();

                tempDate = Control.VisibleDate;

                String abbreviatedYearMonthPattern = AbbreviateMonthPattern(currentDateTimeInfo.YearMonthPattern);

                // This is to be consistent with ASP.NET Calendar control
                // on handling YearMonthPattern:
                // Some cultures have a comma in their YearMonthPattern,
                // which does not look right in a calendar.  Here we
                // strip the comma off.
                int indexComma = abbreviatedYearMonthPattern.IndexOf(',');
                if (indexComma >= 0)
                {
                    abbreviatedYearMonthPattern =
                        abbreviatedYearMonthPattern.Remove(indexComma, 1);
                }

                arr = new ArrayList();
                for (int i = 0; i < _monthsToDisplay; i++)
                {
                    arr.Add(tempDate.ToString(abbreviatedYearMonthPattern, CultureInfo.CurrentCulture));
                    tempDate = _threadCalendar.AddMonths(tempDate, 1);
                }
                arr.Add(GetDefaultLabel(NextLabel));
                arr.Add(GetDefaultLabel(PreviousLabel));

                DataBindAndRender(writer, _monthList, arr);
                break;

            // Based on the month selected in case ChooseMonth above, render a list of
            // availabe weeks of the month.
            case ChooseWeek:
                String monthFormat = (GetNumericDateFormat()[0] == 'y') ? "yyyy/M" : "M/yyyy";
                writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseWeek));
                writer.Write(" (");
                writer.Write(Control.VisibleDate.ToString(monthFormat, CultureInfo.CurrentCulture));
                writer.Write("):");
                writer.WriteBreak();

                // List weeks of days of the selected month.  May include
                // days from the previous and the next month to fill out
                // all six week choices.  This is consistent with the
                // ASP.NET Calendar control.

                // Note that the event handling code of this list control
                // should be implemented according to the index content
                // generated here.

                tempDate = FirstCalendarDay(Control.VisibleDate);

                arr = new ArrayList();
                String weekDisplay;
                for (int i = 0; i < 6; i++)
                {
                    weekDisplay  = tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture);
                    weekDisplay += DaySeparator;
                    tempDate     = _threadCalendar.AddDays(tempDate, 6);
                    weekDisplay += tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture);
                    arr.Add(weekDisplay);
                    tempDate = _threadCalendar.AddDays(tempDate, 1);
                }

                DataBindAndRender(writer, _weekList, arr);
                break;

            // Based on the month and week selected in case ChooseMonth and ChooseWeek above,
            // render a list of the dates in the week.
            case ChooseDay:
                writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseDate));
                writer.Write(":");
                writer.WriteBreak();

                tempDate = Control.VisibleDate;

                arr = new ArrayList();
                String        date;
                String        dayName;
                StringBuilder dayDisplay   = new StringBuilder();
                bool          dayNameFirst = (GetNumericDateFormat()[0] != 'y');

                for (int i = 0; i < 7; i++)
                {
                    date = tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture);

                    if (Control.ShowDayHeader)
                    {
                        // Use the short format for displaying day name
                        dayName           = GetAbbreviatedDayName(tempDate);
                        dayDisplay.Length = 0;

                        if (dayNameFirst)
                        {
                            dayDisplay.Append(dayName);
                            dayDisplay.Append(Space);
                            dayDisplay.Append(date);
                        }
                        else
                        {
                            dayDisplay.Append(date);
                            dayDisplay.Append(Space);
                            dayDisplay.Append(dayName);
                        }
                        arr.Add(dayDisplay.ToString());
                    }
                    else
                    {
                        arr.Add(date);
                    }
                    tempDate = _threadCalendar.AddDays(tempDate, 1);
                }

                DataBindAndRender(writer, _dayList, arr);
                break;

            default:
                Debug.Assert(false, "Unexpected Secondary UI Mode");
                break;
            }

            writer.ExitStyle(Style, breakAfter);
        }
コード例 #10
0
ファイル: DatePeriod.cs プロジェクト: ehsan-davoudi/webstack
        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");
                }
            }
        }
コード例 #11
0
        public void UpdateMonthMode()
        {
            Debug.Assert(this._owner.DisplayDate != null);
            _currentMonth = (DateTime)this._owner.DisplayDate;


            _firstDayOfWeek = this._owner.FirstDayOfWeek;

            if (_currentMonth != null)
            {
                int      year            = _calendar.GetYear(_currentMonth);
                int      month           = _calendar.GetMonth(_currentMonth);
                DateTime firstDayOfMonth = new DateTime(year, month, 1);

                if (this._headerButton != null)
                {
                    this._headerButton.Content = string.Format(CultureInfo.CurrentCulture, Resource.Calendar_MonthViewHeaderText,
                                                               CultureInfo.CurrentCulture.DateTimeFormat.MonthNames[month - 1],
                                                               year.ToString(CultureInfo.CurrentCulture));

                    this._headerButton.IsEnabled = true;
                }

                int      lastMonthToDisplay  = PreviousMonthDays(firstDayOfMonth);
                DateTime dateToAdd           = _calendar.AddDays(firstDayOfMonth, -lastMonthToDisplay);
                DateTime firstDayOfNextMonth = _calendar.AddMonths(firstDayOfMonth, 1);

                // check to see if Prev/Next Buttons will be displayed
                if (_previousButton != null)
                {
                    if (DateTime.Compare(_owner.DisplayDateStart.GetValueOrDefault(DateTime.MinValue), firstDayOfMonth) > -1)
                    {
                        _previousButton.IsEnabled = false;
                    }
                    else
                    {
                        _previousButton.IsEnabled = true;
                    }
                }

                if (_nextButton != null)
                {
                    if (DateTime.Compare(_owner.DisplayDateEnd.GetValueOrDefault(DateTime.MaxValue), firstDayOfNextMonth) < 0)
                    {
                        _nextButton.IsEnabled = false;
                    }
                    else
                    {
                        _nextButton.IsEnabled = true;
                    }
                }

                int count = 0;

                if (_monthGrid != null)
                {
                    Debug.Assert(_monthGrid.Children.Count == COLS * ROWS);
                    //Set the day titles
                    foreach (object child in _monthGrid.Children)
                    {
                        if (count < (COLS))
                        {
                            //this assumes that the day titles are always text blocks
                            TextBlock daytitle = child as TextBlock;
                            Debug.Assert(daytitle != null);
                            daytitle.Text = CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedDayNames[(count + (int)_firstDayOfWeek) % NUMBER_OF_DAYS_IN_WEEK];
                        }
                        else
                        {
                            DayButton mybutton = child as DayButton;
                            Debug.Assert(mybutton != null);

                            SetButtonState(mybutton, dateToAdd);

                            mybutton.IsTabStop = false;

                            if (_currentButton == null)
                            {
                                if (_owner.SelectedDate == null && mybutton.IsToday)
                                {
                                    mybutton.IsTabStop = true;
                                    _currentButton     = mybutton;
                                    mybutton.IsCurrent = true;
                                }
                                else
                                {
                                    if (mybutton.IsSelected)
                                    {
                                        mybutton.IsTabStop = true;
                                        _currentButton     = mybutton;
                                        mybutton.IsCurrent = true;
                                    }
                                }
                            }

                            mybutton.Content     = String.Format(CultureInfo.CurrentCulture, "{0,2}", dateToAdd.Day);
                            mybutton.DataContext = dateToAdd;
                            dateToAdd            = _calendar.AddDays(dateToAdd, 1);
                        }
                        count++;
                    }
                }
            }
        }
コード例 #12
0
        public static DateTime EndOfSemester( this DateTime date, Calendar calendar )
        {
            Arg.NotNull( calendar, nameof( calendar ) );
            Contract.Ensures( calendar.GetYear( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetYear( date ) ) );
            Contract.Ensures( Contract.Result<DateTime>().Semester( calendar ) == Contract.OldValue( date.Semester( calendar ) ) );

            return calendar.AddMonths( date.StartOfSemester( calendar ), 6 ).AddTicks( -1L );
        }
コード例 #13
0
        public static DateTime StartOfSemester( this DateTime date, Calendar calendar )
        {
            Arg.NotNull( calendar, nameof( calendar ) );
            Contract.Ensures( calendar.GetYear( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetYear( date ) ) );
            Contract.Ensures( Contract.Result<DateTime>().Semester( calendar ) == Contract.OldValue( date.Semester( calendar ) ) );

            var semester = date.Semester( calendar );
            return calendar.AddMonths( date.StartOfYear( calendar ), ( semester - 1 ) * 6 );
        }