internal static unsafe bool TryParse(string s, DateTimeFormatInfo dtfi, DateTimeStyles styles, ref DateTimeResult result)
{
DateTime time;
if (s == null)
{
result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "s");
return false;
}
if (s.Length == 0)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
DS bEGIN = DS.BEGIN;
bool flag = false;
DateTimeToken dtok = new DateTimeToken {
suffix = TokenType.SEP_Unk
};
DateTimeRawInfo raw = new DateTimeRawInfo();
int* numberBuffer = stackalloc int[3];
raw.Init(numberBuffer);
result.calendar = dtfi.Calendar;
result.era = 0;
__DTString str = new __DTString(s, dtfi);
str.GetNext();
do
{
if (!Lex(bEGIN, ref str, ref dtok, ref raw, ref result, ref dtfi))
{
return false;
}
if (dtok.dtt != DTT.Unk)
{
if (dtok.suffix != TokenType.SEP_Unk)
{
if (!ProcessDateTimeSuffix(ref result, ref raw, ref dtok))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
dtok.suffix = TokenType.SEP_Unk;
}
if (dtok.dtt == DTT.NumLocalTimeMark)
{
switch (bEGIN)
{
case DS.D_YNd:
case DS.D_YN:
return ParseISO8601(ref raw, ref str, styles, ref result);
}
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
bEGIN = dateParsingStates[(int) bEGIN][(int) dtok.dtt];
if (bEGIN == DS.ERROR)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (bEGIN > DS.ERROR)
{
if ((dtfi.FormatFlags & DateTimeFormatFlags.UseHebrewRule) != DateTimeFormatFlags.None)
{
if (!ProcessHebrewTerminalState(bEGIN, ref result, ref styles, ref raw, dtfi))
{
return false;
}
}
else if (!ProcessTerminaltState(bEGIN, ref result, ref styles, ref raw, dtfi))
{
return false;
}
flag = true;
bEGIN = DS.BEGIN;
}
}
}
while (((dtok.dtt != DTT.End) && (dtok.dtt != DTT.NumEnd)) && (dtok.dtt != DTT.MonthEnd));
if (!flag)
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
AdjustTimeMark(dtfi, ref raw);
if (!AdjustHour(ref result.Hour, raw.timeMark))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
bool bTimeOnly = ((result.Year == -1) && (result.Month == -1)) && (result.Day == -1);
if (!CheckDefaultDateTime(ref result, ref result.calendar, styles))
{
return false;
}
if (!result.calendar.TryToDateTime(result.Year, result.Month, result.Day, result.Hour, result.Minute, result.Second, 0, result.era, out time))
{
result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
return false;
}
if (raw.fraction > 0.0)
{
time = time.AddTicks((long) Math.Round((double) (raw.fraction * 10000000.0)));
}
if ((raw.dayOfWeek != -1) && (raw.dayOfWeek != result.calendar.GetDayOfWeek(time)))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDayOfWeek", null);
return false;
}
result.parsedDate = time;
if (!DetermineTimeZoneAdjustments(ref result, styles, bTimeOnly))
{
return false;
}
return true;
}