Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ IsValidCustomDateFormat()

static bool System.DateTimeFormat.IsValidCustomDateFormat ( ReadOnlySpan< char > format,
bool throwOnError )
inlinestaticpackage

Definition at line 687 of file DateTimeFormat.cs.

688 {
689 int i = 0;
690 while (i < format.Length)
691 {
692 switch (format[i])
693 {
694 case '\\':
695 if (i == format.Length - 1)
696 {
697 if (throwOnError)
698 {
699 throw new FormatException(SR.Format_InvalidString);
700 }
701 return false;
702 }
703 i += 2;
704 break;
705 case '"':
706 case '\'':
707 {
708 char c;
709 for (c = format[i++]; i < format.Length && format[i] != c; i++)
710 {
711 }
712 if (i >= format.Length)
713 {
714 if (throwOnError)
715 {
716 throw new FormatException(SR.Format(SR.Format_BadQuote, c));
717 }
718 return false;
719 }
720 i++;
721 break;
722 }
723 case ':':
724 case 'F':
725 case 'H':
726 case 'K':
727 case 'f':
728 case 'h':
729 case 'm':
730 case 's':
731 case 't':
732 case 'z':
733 if (throwOnError)
734 {
735 throw new FormatException(SR.Format_InvalidString);
736 }
737 return false;
738 default:
739 i++;
740 break;
741 }
742 }
743 return true;
744 }

References System.SR.Format(), System.format, System.SR.Format_BadQuote, and System.SR.Format_InvalidString.

Referenced by System.DateOnly.ToString(), and System.DateOnly.TryFormat().