pjfanning opened a new pull request, #133: URL: https://github.com/apache/poi-xmlbeans/pull/133
`SampleXmlUtil.formatDate` ignored min/max facets on every date type except `dateTime`, and didn't respect them properly on `dateTime` either. **Why** - The random seed is a full dateTime. It was compared against the bounds *before* `setBuiltinTypeCode` cut it down to the facet's type. For `date`, `time`, `gYear`, `gYearMonth`, `gMonth`, `gMonthDay` and `gDay`, `compareToGDate` therefore always returned 2 (incomparable). The min check (`>= 0`) never matched, so the min branch never ran, and the max check (`<= 0`) let everything through. - When a reset did fire, it added or subtracted 1–8 hours from the *random* date, not from the bound. So `minInclusive 2100-01-01T00:00:00Z` produced values like `2014-01-05T11:16:42.000+00:00`. - The min/max checks also treated an incomparable result (2) inconsistently. The same issue in the validator's min checks is handled in #132. **Fix** - Cut the seed down to the type and decide its timezone first. - Check the seed against all four facets the way validation does, counting an incomparable result as out of range. - If the seed misses, try the bound itself (which suits the inclusive facets), then the bound stepped inwards by the smallest unit the type shows (P1Y, P1M, P1D, then PT1H down to PT0.001S for the time types). - For partial types (gDay, gMonthDay etc.), fill in the missing fields before doing the arithmetic, then drop them again. This also replaces the eight near-identical per-type blocks with one facet lookup. `formatDuration` clamps field by field and has similar issues, but this PR leaves it alone. **Tests** `Xsd2InstTest.testDateSamplesSatisfyTheirBounds` generates samples for 12 facet/type combinations and validates each one against its schema. On trunk it fails on the first case. With the fix it passes, and it also passed locally with 2000 iterations per case. `./gradlew test` is green. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
