Skip to content

fix(2.0): streamline ISO 8601 duration - #1206

Open
cvas22 wants to merge 4 commits into
CycloneDX:2.0-devfrom
cvas22:fix/1203-iso8601-duration
Open

cvas22 wants to merge 4 commits into
CycloneDX:2.0-devfrom
cvas22:fix/1203-iso8601-duration

Conversation

@cvas22

@cvas22 cvas22 commented Nov 12, 2026 •

Copy link
Copy Markdown

Fixes #1203

This adds a duration def to common, next to timestamp, and points the five duration properties at it: blueprint reviewFrequency and risk timeframe, downtime, recovery and horizon. Descriptions now all link ISO 8601 the same way, and the examples live only on the shared def.

Following the review, the pattern is kept minimal (^P plus minLength: 3) with a $comment explaining why. The full ISO 8601 syntax, including fractions and weeks, is left to the standard instead of being repeated as a regex here.

Tests: a valid blueprint with a time part, an invalid one with a bare P, and an invalid risk timeframe that's free text.

Add a duration def to common and use it for blueprint reviewFrequency and
the risk timeframe, downtime, recovery and horizon properties. The pattern
accepts the time part that reviewFrequency was missing, rejects weeks mixed
with other designators, and timeframe and horizon now have a pattern at all.

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@cvas22
cvas22 requested a review from a team as a code owner November 12, 2026 01:04
@jkowalleck jkowalleck linked an issue Nov 12, 2026 that may be closed by this pull request
@jkowalleck

Copy link
Copy Markdown
Member

we had some changes in the docs lately.
@cvas22 , could you rebase your changes?

@jkowalleck jkowalleck added this to the 2.0 milestone Nov 12, 2026
@jkowalleck jkowalleck added defect CDX 2.0 related to release v2.0 labels Nov 12, 2026
…-duration

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>

# Conflicts:
#	schema/2.0/modules/cyclonedx-blueprint-2.0.schema.json
#	schema/2.0/modules/cyclonedx-risk-2.0.schema.json
@cvas22

cvas22 commented Nov 12, 2026

Copy link
Copy Markdown
Author

Merged 2.0-dev in 7d67fe8. The two conflicts were the new examples on reviewFrequency and horizon. I kept the shared duration ref and took the examples and the backtick style. The inline pattern 2.0-dev added to reviewFrequency allows weeks mixed with other units, like P1M2W, which the shared one rejects, so I left the shared one in place. All the new examples match it.

"pattern": "^P(?!$)(\\d+Y)?(\\d+M)?(\\d+W)?(\\d+D)?$",
"description": "ISO 8601 duration for review frequency (e.g., `\"P3M\"` for quarterly).",
"description": "How often the blueprint is reviewed, as an [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) duration, for example `\"P3M\"` for quarterly.",
"examples": ["P1Y", "P3M", "P5W", "P23D"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets remove the examples - we have them at cyclonedx-common-2.0.schema.json#/$defs/duration

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 12abd5a.

"$ref": "cyclonedx-common-2.0.schema.json#/$defs/duration",
"title": "Timeframe",
"description": "The period over which the probability or frequency is assessed, expressed as an [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) duration, for example `\"P1Y\"` for one year.",
"examples": ["P1Y", "P1M", "P23DT23H", "PT1M"]

@jkowalleck jkowalleck Nov 13, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the examples, we already have them in
cyclonedx-common-2.0.schema.json#/$defs/duration

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 12abd5a, and the ones on horizon too.

"duration": {
"type": "string",
"title": "Duration",
"pattern": "^P(?!$)((\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+(\\.\\d+)?S)?)?|\\d+W)$",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per spec .

The smallest value used may also have a decimal fraction,[45] as in "P0.5Y" to indicate half a year. This decimal fraction may be specified with either a comma or a full stop, as in "P0,5Y" or "P0.5Y"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recomemnded action: #1206 (comment)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I had that wrong. With the minimal pattern in 12abd5a this isn't an issue anymore.

"duration": {
"type": "string",
"title": "Duration",
"pattern": "^P(?!$)((\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+(\\.\\d+)?S)?)?|\\d+W)$",

@jkowalleck jkowalleck Nov 13, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading the ISO 8601 duration spec again and again, i recommend not using any complex format - it is in the obligation of the downstream users to adhere to the respective spec in full.

therefore, i recommend

  • using this minimal "pattern": "^P"
  • add "minLength": 3 (as in P1Y)
  • adjust the descitption to be minimal and reference the spec
    [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) duration
  • add a comment that explains that we dont want to duplicate an existing standard by adding a complex regex here.

@stevespringett WDYT?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, went with that in 12abd5a. The weeks test became a check that a bare P is rejected.

@jkowalleck jkowalleck changed the title fix(2.0): share one ISO 8601 duration definition fix(2.0): streamline ISO 8601 duration Nov 13, 2026
The pattern now only checks the leading P and a minimum length, and the
full syntax is left to ISO 8601 itself.

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CDX 2.0 related to release v2.0 defect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[2.0] fix & streamline ISO 8601 duration

2 participants