/// <summary>
        /// Gets the abbreviated or full month name for the specified <paramref name="month"/> and <paramref name="year"/> value,
        /// using the <paramref name="nameProvider"/> if not null or the <see cref="DateTimeFormatInfo"/> specified by <paramref name="info"/>.
        /// </summary>
        /// <param name="month">The month value to get the month name for.</param>
        /// <param name="year">The year value to get the month name for.</param>
        /// <param name="info">The <see cref="DateTimeFormatInfo"/> value to use.</param>
        /// <param name="nameProvider">The <see cref="ICustomFormatProvider"/> to get the name.
        /// This parameter has precedence before the <paramref name="info"/>. Can be <c>null</c>.</param>
        /// <param name="abbreviated">true to get the abbreviated month name; false otherwise.</param>
        /// <returns>The full or abbreviated month name specified by <paramref name="month"/> and <paramref name="year"/>.</returns>
        private static string GetMonthName(int month, int year, DateTimeFormatInfo info, ICustomFormatProvider nameProvider, bool abbreviated)
        {
            if (nameProvider != null)
            {
                return(abbreviated
                      ? nameProvider.GetAbbreviatedMonthName(year, month)
                      : nameProvider.GetMonthName(year, month));
            }

            return(abbreviated ? info.GetAbbreviatedMonthName(month) : info.GetMonthName(month));
        }
Beispiel #2
0
        /// <summary>
        /// Gets the abbreviated or full month name for the specified <paramref name="month"/> and <paramref name="year"/> value, using the
        /// <paramref name="nameProvider"/> if not null or the <see cref="DateTimeFormatInfo"/> specified by <paramref name="info"/>.
        /// </summary>
        /// <param name="month">
        /// The month value to get the month name for.
        /// </param>
        /// <param name="year">
        /// The year value to get the month name for.
        /// </param>
        /// <param name="info">
        /// The <see cref="DateTimeFormatInfo"/> value to use.
        /// </param>
        /// <param name="nameProvider">
        /// The <see cref="ICustomFormatProvider"/> to get the name. This parameter has precedence before the
        /// <paramref name="info"/>. Can be <c>null</c>.
        /// </param>
        /// <param name="abbreviated">
        /// true to get the abbreviated month name; false otherwise.
        /// </param>
        /// <returns>
        /// The full or abbreviated month name specified by <paramref name="month"/> and <paramref name="year"/>.
        /// </returns>
        private static string GetMonthName(int month, int year, DateTimeFormatInfo info, ICustomFormatProvider nameProvider, bool abbreviated)
        {
            if (nameProvider != null)
            {
                return abbreviated ? nameProvider.GetAbbreviatedMonthName(year, month) : nameProvider.GetMonthName(year, month);
            }

            return abbreviated ? info.GetAbbreviatedMonthName(month) : info.GetMonthName(month);
        }
            public string ParsePattern(MonthCalendarDate date, string[] nativeDigits = null)
            {
                // replace date separator with '/'
                string format = this.pattern.Replace(provider.DateSeparator, "/");

                StringBuilder sb = new StringBuilder();

                Calendar c = provider.Calendar;

                int i     = 0;
                int index = 0;

                while (i < format.Length)
                {
                    int    tokLen;
                    char   ch = format[i];
                    string currentString;

                    switch (ch)
                    {
                    case 'd':
                    {
                        tokLen = CountChar(format, i, ch);

                        if (tokLen <= 2)
                        {
                            currentString = DateMethods.GetNumberString(date.Day, nativeDigits, tokLen == 2);

                            this.isDayNumber = true;

                            this.dayString = currentString;

                            this.dayPartIndex = index++;

                            this.dayIndex = sb.Length;
                        }
                        else
                        {
                            currentString = tokLen == 3 ? provider.GetAbbreviatedDayName(c.GetDayOfWeek(date.Date)) : provider.GetDayName(c.GetDayOfWeek(date.Date));

                            this.dayNameString = currentString;
                        }

                        sb.Append(currentString);

                        break;
                    }

                    case 'M':
                    {
                        tokLen = CountChar(format, i, ch);

                        if (tokLen <= 2)
                        {
                            currentString = DateMethods.GetNumberString(date.Month, nativeDigits, tokLen == 2);

                            this.isMonthNumber = true;
                        }
                        else
                        {
                            currentString = tokLen == 3
                                              ? provider.GetAbbreviatedMonthName(date.Year, date.Month)
                                              : provider.GetMonthName(date.Year, date.Month);
                        }

                        this.monthPartIndex = index++;

                        this.monthIndex = sb.Length;

                        this.monthString = currentString;

                        sb.Append(currentString);

                        break;
                    }

                    case 'y':
                    {
                        tokLen = CountChar(format, i, ch);

                        var year = tokLen <= 2 ? date.Year % 100 : date.Year;

                        currentString = DateMethods.GetNumberString(year, nativeDigits, tokLen <= 2);

                        this.yearString = currentString;

                        this.yearPartIndex = index++;

                        this.yearIndex = sb.Length;

                        sb.Append(currentString);

                        break;
                    }

                    case 'g':
                    {
                        tokLen = CountChar(format, i, ch);

                        currentString = provider.GetEraName(c.GetEra(date.Date));

                        this.eraString = currentString;

                        sb.Append(currentString);

                        break;
                    }

                    case '/':
                    {
                        tokLen = CountChar(format, i, ch);

                        sb.Append(provider.DateSeparator);

                        break;
                    }

                    default:
                    {
                        tokLen = 1;

                        sb.Append(ch.ToString(CultureInfo.CurrentUICulture));

                        break;
                    }
                    }

                    i += tokLen;
                }

                return(sb.ToString());
            }
            public string ParsePattern(MonthCalendarDate date)
            {
                // replace date separator with '/'
                string format = pattern.Replace(provider.DateSeparator, "/");

                // reverse pattern if rtl culture
                if (this.provider.IsRTLLanguage)
                {
                    List <char> chars = new List <char>(format.ToCharArray());
                    chars.Reverse();

                    format = new string(chars.ToArray());
                }

                StringBuilder sb = new StringBuilder();
                Calendar      c  = provider.Calendar;

                int i     = 0;
                int index = 0;

                while (i < format.Length)
                {
                    int    tokLen;
                    char   ch = format[i];
                    string currentString;

                    switch (ch)
                    {
                    case 'd':
                    {
                        tokLen = CountChar(format, i, ch);

                        if (tokLen <= 2)
                        {
                            currentString = tokLen == 2 ? date.Day.ToString("##00") : date.Day.ToString();

                            this.isDayNumber = true;

                            this.dayString = currentString;

                            this.dayPartIndex = index++;

                            this.dayIndex = sb.Length;
                        }
                        else
                        {
                            currentString = tokLen == 3 ? provider.GetAbbreviatedDayName(c.GetDayOfWeek(date.Date)) : provider.GetDayName(c.GetDayOfWeek(date.Date));

                            this.dayNameString = currentString;
                        }

                        sb.Append(currentString);

                        break;
                    }

                    case 'M':
                    {
                        tokLen = CountChar(format, i, ch);

                        if (tokLen <= 2)
                        {
                            currentString = tokLen == 2 ? date.Month.ToString("##00") : date.Month.ToString();

                            this.isMonthNumber = true;
                        }
                        else
                        {
                            currentString = tokLen == 3
                                              ? provider.GetAbbreviatedMonthName(date.Year, date.Month)
                                              : provider.GetMonthName(date.Year, date.Month);
                        }

                        this.monthPartIndex = index++;

                        this.monthIndex = sb.Length;

                        this.monthString = currentString;

                        sb.Append(currentString);

                        break;
                    }

                    case 'y':
                    {
                        tokLen = CountChar(format, i, ch);

                        currentString = tokLen <= 2 ? (date.Year % 100).ToString("##00") : date.Year.ToString();

                        this.yearString = currentString;

                        this.yearPartIndex = index++;

                        this.yearIndex = sb.Length;

                        sb.Append(currentString);

                        break;
                    }

                    case 'g':
                    {
                        tokLen = CountChar(format, i, ch);

                        currentString = provider.GetEraName(c.GetEra(date.Date));

                        this.eraString = currentString;

                        sb.Append(currentString);

                        break;
                    }

                    case '/':
                    {
                        tokLen = CountChar(format, i, ch);

                        sb.Append(provider.DateSeparator);

                        break;
                    }

                    default:
                    {
                        tokLen = 1;

                        sb.Append(ch.ToString());

                        break;
                    }
                    }

                    i += tokLen;
                }

                return(sb.ToString());
            }