in csharp/src/Drivers/Apache/Hive2/HiveServer2Reader.cs [320:393]
internal static bool TryParse(ReadOnlySpan<byte> date, out DateTimeOffset dateValue)
{
bool isKnownFormat = date.Length >= KnownFormatDateTimeLength
&& date[YearMonthSepIndex] == AsciiDash
&& date[MonthDaySepIndex] == AsciiDash
&& date[DayHourSepIndex] == AsciiSpace
&& date[HourMinuteSepIndex] == AsciiColon
&& date[MinuteSecondSepIndex] == AsciiColon;
if (!isKnownFormat
|| !Utf8Parser.TryParse(date.Slice(YearIndex, 4), out int year, out int bytesConsumed, standardFormat: 'D') || bytesConsumed != 4
|| !Utf8Parser.TryParse(date.Slice(MonthIndex, 2), out int month, out bytesConsumed, standardFormat: 'D') || bytesConsumed != 2
|| !Utf8Parser.TryParse(date.Slice(DayIndex, 2), out int day, out bytesConsumed, standardFormat: 'D') || bytesConsumed != 2
|| !Utf8Parser.TryParse(date.Slice(HourIndex, 2), out int hour, out bytesConsumed, standardFormat: 'D') || bytesConsumed != 2
|| !Utf8Parser.TryParse(date.Slice(MinuteIndex, 2), out int minute, out bytesConsumed, standardFormat: 'D') || bytesConsumed != 2
|| !Utf8Parser.TryParse(date.Slice(SecondIndex, 2), out int second, out bytesConsumed, standardFormat: 'D') || bytesConsumed != 2)
{
dateValue = default;
return false;
}
try
{
dateValue = new(year, month, day, hour, minute, second, TimeSpan.Zero);
}
catch (ArgumentOutOfRangeException)
{
dateValue = default;
return false;
}
// Retrieve subseconds, if available
int length = date.Length;
if (length > SecondSubsecondSepIndex)
{
if (date[SecondSubsecondSepIndex] == AsciiPeriod)
{
int start = -1;
int end = SubsecondIndex;
while (end < length && (uint)(date[end] - AsciiZero) <= AsciiDigitMaxIndex)
{
if (start == -1) start = end;
end++;
}
if (end < length)
{
// Indicates unrecognized trailing character(s)
dateValue = default;
return false;
}
int subSecondsLength = start != -1 ? end - start : 0;
if (subSecondsLength > 0)
{
if (!Utf8Parser.TryParse(date.Slice(start, subSecondsLength), out int subSeconds, out _))
{
dateValue = default;
return false;
}
double factorOfMilliseconds = Math.Pow(10, subSecondsLength - MillisecondDecimalPlaces);
long ticks = (long)(subSeconds * (TimeSpan.TicksPerMillisecond / factorOfMilliseconds));
dateValue = dateValue.AddTicks(ticks);
}
}
else
{
dateValue = default;
return false;
}
}
return true;
}