in src/Utilities.cs [359:399]
private static DateTime? TryParseDateTimeUtcFromString(string sourceString, DateTimeFormatPattern dateTimeFormat)
{
if (dateTimeFormat == null || string.IsNullOrWhiteSpace(sourceString))
{
return null;
}
if (sourceString.Length < dateTimeFormat.Prefix.Length + dateTimeFormat.Format.Length + dateTimeFormat.Suffix.Length)
{
return null;
}
int startIndex = 0;
while ((startIndex = sourceString.IndexOf(dateTimeFormat.Prefix, startIndex)) >= 0)
{
// Advance post prefix
startIndex += dateTimeFormat.Prefix.Length;
// Look for suffix, skipping the DateTime format part
int suffixStartIndex = sourceString.IndexOf(dateTimeFormat.Suffix, startIndex + dateTimeFormat.Format.Length);
if (suffixStartIndex < 0)
{
// If the suffix cannot be found - we are done searchng for it
break;
}
if (suffixStartIndex - startIndex >= dateTimeFormat.Format.Length)
{
var dateTimePortion = sourceString.Substring(startIndex, suffixStartIndex - startIndex);
DateTime ret;
if (ExtendedDateTime.TryParseExactUtc(dateTimePortion, dateTimeFormat.Format, out ret))
{
return ret;
}
}
}
return null;
}