Repository navigation
ZmanimFormatter.formatXSDDurationTime: valid xsd:duration for negative durations - #301
Merged
Merged
Conversation
…lid xsd:duration Duration.toString() writes a negative duration as "PT-1H-15M-3S", which isn't a valid xsd:duration (XSD only allows one leading sign: "-PT1H15M3S"). This also affected format() with XSD_DURATION_FORMAT and the durations in toXML() / toJSON(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015Er4Sx7LnKzzCbgDEatxkU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The issue
ZmanimFormatter.formatXSDDurationTime(Duration)is documented to return anxsd:duration, but for negative durations it returns a string that isn't a validxsd:duration.The edge case
Any negative
Duration. For example:Duration.ofMinutes(-75)passed directly.format()when the formatter usesXSD_DURATION_FORMAT, whichtoXML()/toJSON()do.What happens
The method returns
Duration.toString(), and Java writes a negative duration with a sign on every field:XML Schema (and ISO 8601) allows only one sign, in front of the whole value:
-PT1H15M3S. So the output is rejected byjavax.xml.datatype.DatatypeFactory.newDuration, by schema validation, and by other XSD / ISO 8601 parsers (for example .NET'sXmlConvert.ToTimeSpan).The fix
For a negative duration, return
"-" + duration.negated().toString(). Zero and positive durations are unchanged.Tests
ZmanimFormatterXsdDurationTestchecks:nullare unchanged.-PT1H15M3Sand-PT0.5Sfor negative durations, and that the result round-trips throughDatatypeFactory.newDurationto the same value.format()withXSD_DURATION_FORMATgives-PT30M.The negative cases fail without the fix.
🤖 Generated with Claude Code
https://claude.ai/code/session_015Er4Sx7LnKzzCbgDEatxkU