Repository: dotnet/runtime
File: src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs (C#)

Code before:
                if (result.Minute != 0 || result.Second != 0 || result.fraction != 0)
                {
                    result.SetBadDateTimeFailure();
                    return false;
                }

                result.Hour = 0;
                isEndOfDay = true;
            }

            if (!parseInfo.calendar.TryToDateTime(result.Year, result.Month, result.Day,
                    result.Hour, result.Minute, result.Second, 0, result.era, out result.parsedDate))
            {
                result.SetFailure(ParseFailureKind.Format_BadDateTimeCalendar);
                return false;
            }
            if (result.fraction > 0)
            {
                if (!result.parsedDate.TryAddTicks((long)Math.Round(result.fraction * TimeSpan.TicksPerSecond), out result.parsedDate))
                {
                    result.SetBadDateTimeFailure();
                    return false;
                }
            }

            // If hour was originally 24 (end of day), add one day to advance to the next day at midnight
            if (isEndOfDay)
            {
                if (!result.parsedDate.TryAddTicks(TimeSpan.TicksPerDay, out result.parsedDate))
                {
                    result.SetBadDateTimeFailure();
                    return false;
                }
            }

            //
            // We have to check day of week before we adjust to the time zone.
            // It is because the value of day of week may change after adjusting
            // to the time zone.
            //
            if (parseInfo.dayOfWeek != -1)
            {
                //
                // Check if day of week is correct.
                //
                if (parseInfo.dayOfWeek != (int)parseInfo.calendar.GetDayOfWeek(result.parsedDate))
                {
                    result.SetFailure(ParseFailureKind.Format_BadDayOfWeek);
                    return false;
                }
            }

Review comment (suggestion):
@copilot could you clarify more the comment telling according to the iso8601 https://www.iso8601.com/
24:00:00 — End of a calendar day (same instant as next day's 00:00:00)

Code after:
                }
                if (result.Hour > 12)
                {
                    // AM/PM is used, but the value for HH is too big.
                    result.SetBadDateTimeFailure();
                    return false;
                }
                if (parseInfo.timeMark == TM.AM)
                {
                    if (result.Hour == 12)
                    {
                        result.Hour = 0;
                    }
                }
                else
                {
                    result.Hour = (result.Hour == 12) ? 12 : result.Hour + 12;
                }
            }
            else
            {
                // Military (24-hour time) mode
                //
                // AM cannot be set with a 24-hour time like 17:15.
                // PM cannot be set with a 24-hour time like 03:15.
                if ((parseInfo.timeMark == TM.AM && result.Hour >= 12)
                    || (parseInfo.timeMark == TM.PM && result.Hour < 12))
                {
                    result.SetBadDateTimeFailure();
                    return false;
                }
            }

            // Check if the parsed string only contains hour/minute/second values.
            bool bTimeOnly = (result.Year == -1 && result.Month == -1 && result.Day == -1);
            if (!CheckDefaultDateTime(ref result, ref parseInfo.calendar, styles))
            {
                return false;
            }

            if (!bTimeOnly && dtfi.HasYearMonthAdjustment)
            {
                if (!dtfi.YearMonthAdjustment(ref result.Year, ref result.Month, (result.flags & ParseFlags.ParsedMonthName) != 0))
                {
                    result.SetFailure(ParseFailureKind.Format_BadDateTimeCalendar);
                    return false;
                }
            }

            // Per ISO 8601:2004, 24:00:00 represents the end of a calendar day
            // (the same instant as the next day's 00:00:00), but only when minute, second, and fraction are all zero.