예제 #1
0
        /// <summary>
        /// Sets the culture-specific day of week style.
        /// </summary>
        /// <param name="cultureName">A string that specify the name of culture to set the <paramref name="dayOfWeekStyle"/> for.</param>
        /// <param name="dayOfWeekStyle">A <see cref="DayOfWeekStyle"/> to be set.</param>
        /// <exception cref="ArgumentNullException"><paramref name="cultureName"/> is null.</exception>
        public static void SetDayOfWeekStyle(string cultureName, DayOfWeekStyle dayOfWeekStyle)
        {
            if (cultureName is null)
            {
                throw new ArgumentNullException(nameof(cultureName));
            }

            _cultureDayOfWeekStyles[cultureName] = dayOfWeekStyle;
            DiscardFormatInfoCache(cultureName);
        }
예제 #2
0
        static CalendarFormatInfo()
        {
            SetYearPattern(JapaneseCultureNames, "yyyy" + CJKYearSuffix);
            SetYearPattern(ZhongwenCultureNames, "yyyy" + CJKYearSuffix);
            SetYearPattern(KoreanCultureNames, "yyyy" + KoreanYearSuffix);

            var dayOfWeekStyle = new DayOfWeekStyle(LongDayOfWeek, string.Empty, false);

            SetDayOfWeekStyle(JapaneseCultureNames, dayOfWeekStyle);
            SetDayOfWeekStyle(ZhongwenCultureNames, dayOfWeekStyle);
        }
예제 #3
0
        /// <summary>
        /// Sets the culture-specific day of week style.
        /// </summary>
        /// <param name="cultureNames">An array of string that specify the name of culture to set the <paramref name="dayOfWeekStyle"/> for.</param>
        /// <param name="dayOfWeekStyle">A <see cref="DayOfWeekStyle"/> to be set.</param>
        /// <exception cref="ArgumentNullException"><paramref name="cultureNames"/> is null.</exception>
        public static void SetDayOfWeekStyle(string[] cultureNames, DayOfWeekStyle dayOfWeekStyle)
        {
            if (cultureNames is null)
            {
                throw new ArgumentNullException(nameof(cultureNames));
            }

            foreach (var cultureName in cultureNames)
            {
                SetDayOfWeekStyle(cultureName, dayOfWeekStyle);
            }
        }
예제 #4
0
        /// <summary>
        /// Creates a <see cref="CalendarFormatInfo"/> from the <see cref="CultureInfo"/>.
        /// </summary>
        /// <param name="cultureInfo">A <see cref="CultureInfo"/> that specifies the culture to get the date format.</param>
        /// <returns>The <see cref="CalendarFormatInfo"/> object that this method creates.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="cultureInfo"/> is null.</exception>
        public static CalendarFormatInfo FromCultureInfo(CultureInfo cultureInfo)
        {
            if (cultureInfo is null)
            {
                throw new ArgumentNullException(nameof(cultureInfo));
            }

            CalendarFormatInfo calendarInfo;

            if (_formatInfoCache.TryGetValue(cultureInfo.Name, out calendarInfo))
            {
                return(calendarInfo);
            }

            var dateTimeFormat = cultureInfo.DateTimeFormat;

            string yearPattern;

            if (!_cultureYearPatterns.TryGetValue(cultureInfo.Name, out yearPattern))
            {
                yearPattern = "yyyy";
            }

            DayOfWeekStyle dayOfWeekStyle;

            if (!_cultureDayOfWeekStyles.TryGetValue(cultureInfo.Name, out dayOfWeekStyle))
            {
                dayOfWeekStyle = DayOfWeekStyle.Parse(dateTimeFormat.LongDatePattern);
            }

            var monthDayPattern = dateTimeFormat.MonthDayPattern.Replace("MMMM", "MMM");

            if (dayOfWeekStyle.IsFirst)
            {
                calendarInfo = new CalendarFormatInfo(dateTimeFormat.YearMonthPattern,
                                                      monthDayPattern,
                                                      dayOfWeekStyle.Pattern + dayOfWeekStyle.Separator,
                                                      yearPattern);
            }
            else
            {
                calendarInfo = new CalendarFormatInfo(dateTimeFormat.YearMonthPattern,
                                                      dayOfWeekStyle.Pattern,
                                                      monthDayPattern + dayOfWeekStyle.Separator,
                                                      yearPattern);
            }
            _formatInfoCache[cultureInfo.Name] = calendarInfo;
            return(calendarInfo);
        }