private string GetTimeSpanPattern(TimeSpanPatternType patternType, char format)
        {
            switch (format)
            {
            case 'c':
                return(DefaultPattern);

            case 'g':
                return(ShortPattern);

            case 'G':
                return(LongPattern);

            case 'f':
                return(patternType == TimeSpanPatternType.Formatting ? TimeSpanResources.TimeSpanWordFormat : TimeSpanResources.TimeSpanWordPattern);

            case 'j':
                return(patternType == TimeSpanPatternType.Formatting ? TimeSpanResources.TimeSpanJiraFormat : TimeSpanResources.TimeSpanJiraPattern);

            case 'x':
                return(ISO8601Pattern);

            default:
                throw new ArgumentException("Invalid format specified.", nameof(format));
            }
        }
        /// <summary>
        /// Returns all the standard patterns in which <see cref="TimeSpan"/> values can be formatted.
        /// </summary>
        /// <param name="patternType">Type of the pattern.</param>
        /// <returns>
        /// An array containing the standard patterns in which <see cref="TimeSpan"/> values can be formatted.
        /// </returns>
        public string[] GetAllTimeSpanPatterns(TimeSpanPatternType patternType)
        {
            var output = new List <string>();

            foreach (var f in standardPatternsArray.ToCharArray())
            {
                output.AddRange(GetAllTimeSpanPatterns(patternType, f));
            }
            return(output.ToArray());
        }
 private string GetTimeSpanPattern(TimeSpanPatternType patternType, char format)
 {
     return(format switch
     {
         'c' => DefaultPattern,
         'g' => ShortPattern,
         'G' => LongPattern,
         'f' => patternType == TimeSpanPatternType.Formatting ? Properties.Resources.TimeSpanWordFormat : Properties.Resources.TimeSpanWordPattern,
         'j' => patternType == TimeSpanPatternType.Formatting ? Properties.Resources.TimeSpanJiraFormat : Properties.Resources.TimeSpanJiraPattern,
         'x' => ISO8601Pattern,
         _ => throw new ArgumentException("Invalid format specified.", nameof(format)),
     });
        private string GetCustomFormatString(TimeSpanPatternType patternType, string format, out string zeroFormat)
        {
            var fmt = string.IsNullOrEmpty(format) ? 'c' : format[0];

            zeroFormat = string.IsNullOrEmpty(TimeSpanZeroDisplay) ? string.Empty : TimeSpanZeroDisplay;
            if (format != null && format.Length > 1)
            {
                if (format[0] == ';')
                {
                    fmt        = 'c';
                    zeroFormat = format.Substring(1);
                }
                else if (format[0] != '\\' && format[1] == ';')
                {
                    zeroFormat = format.Substring(2);
                }
                else
                {
                    return(format);
                }
            }
            return(validFormats.IndexOf(fmt) >= 0 ? GetTimeSpanPattern(patternType, fmt) : format);
        }
 /// <summary>
 /// Returns all the standard patterns in which <see cref="TimeSpan"/> values can be formatted using the specified format pattern.
 /// </summary>
 /// <param name="patternType">Type of the pattern.</param>
 /// <param name="format">A standard format pattern.</param>
 /// <returns>
 /// An array containing the standard patterns in which <see cref="TimeSpan"/> values can be formatted using the specified format pattern.
 /// </returns>
 public string[] GetAllTimeSpanPatterns(TimeSpanPatternType patternType, char format) => new[] { GetTimeSpanPattern(patternType, format) };