Support ISO 8601 24:00:00 (endOfDayFrag) in XSD DateTime validation#124437
Support ISO 8601 24:00:00 (endOfDayFrag) in XSD DateTime validation#124437
Conversation
Co-authored-by: jeffhandley <[email protected]>
…eTime Co-authored-by: jeffhandley <[email protected]>
Co-authored-by: jeffhandley <[email protected]>
|
@tarekgh Tagged you for review next week. Not urgent. |
|
@copilot invoke the code-review skill and post your analysis/results as a comment on this pr |
🤖 Copilot Code Review — PR #124437Holistic AssessmentMotivation: Real bug. The W3C XML Schema specification explicitly defines Approach: The approach is sound — it fixes the parser to accept hour=24 (with minute/second/fraction=0 constraint), then normalizes to hour=0 + next day in the initialization method, with overflow protection for 9999-12-31T24:00:00. Summary: Detailed Findings✅ Correctness —
|
|
@copilot could you address the test suggestions mentioned in the comment #124437 (comment)? |
src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDateTime.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: tarekgh <[email protected]>
…th DateTimeKind; remove section separators Co-authored-by: tarekgh <[email protected]>
Addressed in 2cfb49c:
Regarding the XDR coverage suggestion: |
|
Thanks, @tarekgh. Good catches! |
|
/ba-g the failure is unrelated Android issue. |
Description
XML Schema validation rejected
24:00:00(endOfDayFrag) even though W3C XML Schema 1.1 Part 2 explicitly defines it as valid. PR #124142 added the underlying ISO 8601 24:00 support toDateTime/DateTimeOffset/TimeOnlyparsing; this extends that support to the XSD layer used byXmlConvertand XML Schema validation.Changes
XsdDateTime.ParseTime():hour < 24→hour <= 24, with post-parse validation rejecting hour=24 when minute, second, or fraction are non-zeroXsdDateTime.InitiateXsdDateTime()→TryInitiateXsdDateTime(): When hour=24, sets hour=0 and adds one day. Returnsfalseon overflow (e.g.,9999-12-31T24:00:00) instead of throwing. IncludesDebug.Assertto validate the minute/second/fraction=0 invariant when hour=24s_maxDateTimeTicksForEndOfDaystatic field: Caches theDateTime.MaxValue.Ticks - TimeSpan.TicksPerDayoverflow threshold to avoid recomputationTryParse()/ constructor: Updated to useTryInitiateXsdDateTimefor exception-free overflow handlingxs:dateTime,xs:time, XDR variants; schema validation end-to-end; leap year/year boundary transitions; fractional seconds; overflow; regression coverage for hours 0–23. Tests use consolidatedAssert.Equal(new DateTime(..., expectedKind))assertions withDateTimeKindvalidation.Breaking change considerations
This is a relaxation — previously rejected inputs now parse successfully:
2007-04-05T24:00:00→2007-04-06T00:00:00(wasFormatException)24:00:00asxs:time→ valid (was validation error)24:01:00,24:00:01,24:00:00.0000001remain invalid9999-12-31T24:00:00remains invalid (DateTime overflow)00:00:00on the next day, not the original24:00:00input — consistent with ISO 8601 semantic equivalenceCode relying on
FormatExceptionfor24:00:00inputs or on schema validation rejecting them will observe changed behavior.Adjacent scope
All XSD types with time components share the same
ParseTime()path:xs:dateTime,xs:time, and XDR datetime/time variants are all covered. Types without time components (xs:date,xs:gYear, etc.) are unaffected.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.