Пример #1
0
        public string[] GetMonthNames(MonthStyle style)
        {
            Dictionary <string, string[]> dictionary = GetMonthNames();

            switch (style)
            {
            case MonthStyle.Short:
                return((string[])dictionary["short"].Clone());

            case MonthStyle.Narrow:
                return((string[])dictionary["narrow"].Clone());

            default:
                return((string[])dictionary["long"].Clone());
            }
        }
Пример #2
0
        private static string ParseDateTimeFormat(string format, out DateTimePartStyles style)
        {
            WeekdayStyle             weekday      = default;
            EraStyle                 era          = default;
            MonthStyle               month        = default;
            NumericDateTimePartStyle year         = default;
            NumericDateTimePartStyle day          = default;
            NumericDateTimePartStyle hour         = default;
            NumericDateTimePartStyle minute       = default;
            NumericDateTimePartStyle second       = default;
            TimeZoneNameStyle        timeZoneName = default;
            bool   isHour12 = false;
            string pattern  = Regex.Replace(format, "('([^']*)'|(?<d>[yMLdGEcabBhHkKmszv])(\\k<d>)*)", m => {
                switch (m.Value[0])
                {
                case 'y':
                    year = m.Length == 2 ? NumericDateTimePartStyle.TwoDigit : NumericDateTimePartStyle.Numeric;
                    return("{year}");

                case 'M':
                case 'L':
                    switch (m.Length)
                    {
                    case 1:
                        month = MonthStyle.Numeric;
                        break;

                    case 2:
                        month = MonthStyle.TwoDigit;
                        break;

                    case 3:
                        month = MonthStyle.Short;
                        break;

                    case 4:
                        month = MonthStyle.Long;
                        break;

                    case 5:
                        month = MonthStyle.Narrow;
                        break;
                    }
                    return("{month}");

                case 'd':
                    day = m.Length == 2 ? NumericDateTimePartStyle.TwoDigit : NumericDateTimePartStyle.Numeric;
                    return("{day}");

                case 'E':
                case 'c':
                    weekday = m.Length == 2 ? WeekdayStyle.Short : m.Length == 3 ? WeekdayStyle.Long : WeekdayStyle.Narrow;
                    return("{weekday}");

                case 'G':
                    era = EraStyle.Long;
                    return("{era}");

                case 'a':
                case 'b':
                case 'B':
                    isHour12 = true;
                    return("{ampm}");

                case 'h':
                case 'H':
                case 'k':
                case 'K':
                    hour = m.Length == 2 ? NumericDateTimePartStyle.TwoDigit : NumericDateTimePartStyle.Numeric;
                    return("{hour}");

                case 'm':
                    minute = m.Length == 2 ? NumericDateTimePartStyle.TwoDigit : NumericDateTimePartStyle.Numeric;
                    return("{minute}");

                case 's':
                    second = m.Length == 2 ? NumericDateTimePartStyle.TwoDigit : NumericDateTimePartStyle.Numeric;
                    return("{second}");

                case 'z':
                case 'v':
                    timeZoneName = m.Length == 1 ? TimeZoneNameStyle.Short : TimeZoneNameStyle.Long;
                    return("{timeZoneName}");
                }
                return(m.Length == 2 ? "'" : m.Groups[1].Value);
            });

            style = new DateTimePartStyles(weekday, era, year, month, day, hour, minute, second, timeZoneName, isHour12);
            return(pattern);
        }
Пример #3
0
        public DateTimePartStyles(WeekdayStyle weekday, EraStyle era, NumericDateTimePartStyle year, MonthStyle month, NumericDateTimePartStyle day, NumericDateTimePartStyle hour, NumericDateTimePartStyle minute, NumericDateTimePartStyle second, TimeZoneNameStyle timeZoneName, bool isHour12)
        {
            int value = 0;

            value     |= (int)weekday << 0;
            value     |= (int)era << 3;
            value     |= (int)year << 6;
            value     |= (int)month << 9;
            value     |= (int)day << 12;
            value     |= (int)hour << 15;
            value     |= (int)minute << 18;
            value     |= (int)second << 21;
            value     |= (int)timeZoneName << 24;
            value     |= isHour12 ? 1 << 27 : 0;
            this.value = value;
        }