DayAsPaddedString() public method

public DayAsPaddedString ( [ minDigits ) : string
minDigits [
return string
        /// <summary>
        /// This is the click handler for the 'Display' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Display_Click(object sender, RoutedEventArgs e)
        {
            // This scenario uses the Windows.Globalization.Calendar class to display the parts of a date.

            // Store results here.
            StringBuilder results = new StringBuilder();

            // Create Calendar objects using different constructors.
            Calendar calendar = new Calendar();
            Calendar japaneseCalendar = new Calendar(new[] { "ja-JP" }, CalendarIdentifiers.Japanese, ClockIdentifiers.TwelveHour);
            Calendar hebrewCalendar = new Calendar(new[] { "he-IL" }, CalendarIdentifiers.Hebrew, ClockIdentifiers.TwentyFourHour);

            // Display individual date/time elements.
            results.AppendLine("User's default calendar system: " + calendar.GetCalendarSystem());
            results.AppendLine("Name of Month: " + calendar.MonthAsSoloString());
            results.AppendLine("Day of Month: " + calendar.DayAsPaddedString(2));
            results.AppendLine("Day of Week: " + calendar.DayOfWeekAsSoloString());
            results.AppendLine("Year: " + calendar.YearAsString());
            results.AppendLine();
            results.AppendLine("Calendar system: " + japaneseCalendar.GetCalendarSystem());
            results.AppendLine("Name of Month: " + japaneseCalendar.MonthAsSoloString());
            results.AppendLine("Day of Month: " + japaneseCalendar.DayAsPaddedString(2));
            results.AppendLine("Day of Week: " + japaneseCalendar.DayOfWeekAsSoloString());
            results.AppendLine("Year: " + japaneseCalendar.YearAsString());
            results.AppendLine();
            results.AppendLine("Calendar system: " + hebrewCalendar.GetCalendarSystem());
            results.AppendLine("Name of Month: " + hebrewCalendar.MonthAsSoloString());
            results.AppendLine("Day of Month: " + hebrewCalendar.DayAsPaddedString(2));
            results.AppendLine("Day of Week: " + hebrewCalendar.DayOfWeekAsSoloString());
            results.AppendLine("Year: " + hebrewCalendar.YearAsString());
            results.AppendLine();

            // Display the results
            OutputTextBlock.Text=results.ToString();
        }
 private string ReportCalendarData(Calendar calendar, string calendarLabel)
 {
     string results = calendarLabel + ": " + calendar.GetCalendarSystem() + "\n";
     results += "Name of Month: " + calendar.MonthAsSoloString() + "\n";
     results += "Day of Month: " + calendar.DayAsPaddedString(2) + "\n";
     results += "Day of Week: " + calendar.DayOfWeekAsSoloString() + "\n";
     results += "Year: " + calendar.YearAsString() + "\n";
     results += "\n";
     return results;
 }
Exemplo n.º 3
0
        private void ValidateFormat(
            string culture,
            string calendar,
            string clock,
            DateTimeOffset date,
            string yearAsPaddedString,
            string yearAsString,
            string monthAsPaddedNumericString,
            string monthAsSoloString,
            string monthAsString,
            string monthAsNumericString,
            string dayAsPaddedString,
            string dayAsString,
            string hourAsPaddedString,
            string hourAsString,
            string minuteAsPaddedString,
            string minuteAsString,
            string secondAsPaddedString,
            string secondAsString,
            string nanosecondAsPaddedString,
            string nanosecondAsString,
            string dayOfWeekAsSoloString,
            string dayOfWeekAsString
            )
        {
            var SUT = new WG.Calendar(new[] { culture }, calendar, clock);

            SUT.SetDateTime(date);

            using (new AssertionScope("Calendar Format"))
            {
                SUT.YearAsPaddedString(2).Should().Be(yearAsPaddedString, nameof(yearAsPaddedString));
                SUT.YearAsString().Should().Be(yearAsString, nameof(yearAsString));
                SUT.MonthAsPaddedNumericString(2).Should().Be(monthAsPaddedNumericString, nameof(monthAsPaddedNumericString));
                SUT.MonthAsSoloString().Should().Be(monthAsSoloString, nameof(monthAsSoloString));
                SUT.MonthAsString().Should().Be(monthAsString, nameof(monthAsString));
                SUT.MonthAsNumericString().Should().Be(monthAsNumericString, nameof(monthAsNumericString));
                SUT.DayAsPaddedString(2).Should().Be(dayAsPaddedString, nameof(dayAsPaddedString));
                SUT.DayAsString().Should().Be(dayAsString, nameof(dayAsString));
                SUT.HourAsPaddedString(2).Should().Be(hourAsPaddedString, nameof(hourAsPaddedString));
                SUT.HourAsString().Should().Be(hourAsString, nameof(hourAsString));
                SUT.MinuteAsPaddedString(2).Should().Be(minuteAsPaddedString, nameof(minuteAsPaddedString));
                SUT.MinuteAsString().Should().Be(minuteAsString, nameof(minuteAsString));
                SUT.SecondAsPaddedString(2).Should().Be(secondAsPaddedString, nameof(secondAsPaddedString));
                SUT.SecondAsString().Should().Be(secondAsString, nameof(secondAsString));
                SUT.NanosecondAsPaddedString(2).Should().Be(nanosecondAsPaddedString, nameof(nanosecondAsPaddedString));
                SUT.NanosecondAsString().Should().Be(nanosecondAsString, nameof(nanosecondAsString));
                SUT.DayOfWeekAsSoloString().Should().Be(dayOfWeekAsSoloString, nameof(dayOfWeekAsSoloString));
                SUT.DayOfWeekAsString().Should().Be(dayOfWeekAsString, nameof(dayOfWeekAsString));
            }
        }
 private string ReportCalendarData(Calendar calendar)
 {
     // Display individual date/time elements.
     return string.Format("In {0} time zone:   {1}   {2} {3}, {4}   {5}:{6}:{7} {8}  {9}",
                          calendar.GetTimeZone(),
                          calendar.DayOfWeekAsSoloString(),
                          calendar.MonthAsSoloString(),
                          calendar.DayAsPaddedString(2),
                          calendar.YearAsString(),
                          calendar.HourAsPaddedString(2),
                          calendar.MinuteAsPaddedString(2),
                          calendar.SecondAsPaddedString(2),
                          calendar.PeriodAsString(),
                          calendar.TimeZoneAsString(3));
 }
Exemplo n.º 5
0
        private void UpdateText(Windows.Globalization.Calendar calendar)
        {
            switch (this.owner.ComponentType)
            {
            case DateTimeComponentType.Day:
                this.headerText  = calendar.DayAsPaddedString(2);
                this.contentText = calendar.DayOfWeekAsSoloString();
                break;

            case DateTimeComponentType.Month:
                this.headerText  = calendar.MonthAsPaddedNumericString(2);
                this.contentText = calendar.MonthAsSoloString();
                break;

            case DateTimeComponentType.Year:
                this.headerText = calendar.YearAsPaddedString(4);
                if (calendar.GetCalendarSystem() == Windows.Globalization.CalendarIdentifiers.Gregorian &&
                    DateTime.IsLeapYear(calendar.GetUtcDateTime().Year))
                {
                    this.contentText = InputLocalizationManager.Instance.GetString("LeapYear");
                }
                else
                {
                    this.contentText = " ";
                }
                break;

            case DateTimeComponentType.Hour:
                this.headerText  = calendar.HourAsString();
                this.contentText = string.Empty;
                break;

            case DateTimeComponentType.Minute:
                this.headerText  = calendar.MinuteAsPaddedString(2);
                this.contentText = string.Empty;
                break;

            case DateTimeComponentType.AMPM:
                this.headerText  = calendar.PeriodAsString();
                this.contentText = string.Empty;
                break;
            }

            this.OnPropertyChanged(nameof(this.HeaderText));
            this.OnPropertyChanged(nameof(this.ContentText));
        }
        /// <summary>
        /// This is a helper function to display calendar's properties in presentable format
        /// </summary>
        /// <param name="calendar"></param>
        private String GetCalendarProperties(Calendar calendar)
        {
            StringBuilder returnString = new StringBuilder();
            
            returnString.AppendLine("Calendar system: " + calendar.GetCalendarSystem());
            returnString.AppendLine("Numeral System: " + calendar.NumeralSystem);
            returnString.AppendLine("Resolved Language " + calendar.ResolvedLanguage);
            returnString.AppendLine("Name of Month: " + calendar.MonthAsSoloString());
            returnString.AppendLine("Day of Month: " + calendar.DayAsPaddedString(2));
            returnString.AppendLine("Day of Week: " + calendar.DayOfWeekAsSoloString());
            returnString.AppendLine("Year: " + calendar.YearAsString());
            returnString.AppendLine();

            return(returnString.ToString());
        }