Beispiel #1
0
        internal static string Format(TimeSpan value, string format, IFormatProvider formatProvider)
        {
            if (format == null || format.Length == 0)
            {
                format = "c";
            }
            if (format.Length != 1)
            {
                return(TimeSpanFormat.FormatCustomized(value, format, DateTimeFormatInfo.GetInstance(formatProvider)));
            }
            char ch = format[0];

            switch (ch)
            {
            case 'c':
            case 't':
            case 'T':
                return(TimeSpanFormat.FormatStandard(value, true, format, TimeSpanFormat.Pattern.Minimum));

            case 'g':
            case 'G':
                DateTimeFormatInfo instance = DateTimeFormatInfo.GetInstance(formatProvider);
                format = value._ticks >= 0L ? instance.FullTimeSpanPositivePattern : instance.FullTimeSpanNegativePattern;
                TimeSpanFormat.Pattern pattern = (int)ch != 103 ? TimeSpanFormat.Pattern.Full : TimeSpanFormat.Pattern.Minimum;
                return(TimeSpanFormat.FormatStandard(value, false, format, pattern));

            default:
                throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
            }
        }
Beispiel #2
0
        // Token: 0x060030CD RID: 12493 RVA: 0x000BA424 File Offset: 0x000B8624
        internal static string Format(TimeSpan value, string format, IFormatProvider formatProvider)
        {
            if (format == null || format.Length == 0)
            {
                format = "c";
            }
            if (format.Length != 1)
            {
                return(TimeSpanFormat.FormatCustomized(value, format, DateTimeFormatInfo.GetInstance(formatProvider)));
            }
            char c = format[0];

            if (c == 'c' || c == 't' || c == 'T')
            {
                return(TimeSpanFormat.FormatStandard(value, true, format, TimeSpanFormat.Pattern.Minimum));
            }
            if (c == 'g' || c == 'G')
            {
                DateTimeFormatInfo instance = DateTimeFormatInfo.GetInstance(formatProvider);
                if (value._ticks < 0L)
                {
                    format = instance.FullTimeSpanNegativePattern;
                }
                else
                {
                    format = instance.FullTimeSpanPositivePattern;
                }
                TimeSpanFormat.Pattern pattern;
                if (c == 'g')
                {
                    pattern = TimeSpanFormat.Pattern.Minimum;
                }
                else
                {
                    pattern = TimeSpanFormat.Pattern.Full;
                }
                return(TimeSpanFormat.FormatStandard(value, false, format, pattern));
            }
            throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
        }