diff --git a/cypress/integration/rendering/gantt.spec.js b/cypress/integration/rendering/gantt.spec.js index 2cc67918c..ec33e01aa 100644 --- a/cypress/integration/rendering/gantt.spec.js +++ b/cypress/integration/rendering/gantt.spec.js @@ -647,6 +647,20 @@ describe('Gantt diagram', () => { ); }); + it('should render a gantt diagram excluding a specific date in YYYY-MM-DD HH:mm:ss format', () => { + imgSnapshotTest( + ` + gantt + dateFormat YYYY-MM-DD HH:mm:ss + excludes 2025-07-07 + section Section + A task :a1, 2025-07-04 20:30:30, 2025-07-08 10:30:30 + Another task:after a1, 20h + `, + {} + ); + }); + it("should render when there's a semicolon in the title", () => { imgSnapshotTest( ` diff --git a/packages/mermaid/src/diagrams/gantt/ganttRenderer.js b/packages/mermaid/src/diagrams/gantt/ganttRenderer.js index f5c8c2e38..0695544ce 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttRenderer.js +++ b/packages/mermaid/src/diagrams/gantt/ganttRenderer.js @@ -554,12 +554,14 @@ export const draw = function (text, id, version, diagObj) { return; } - const dateFormat = diagObj.db.getDateFormat(); + const normalizedExcludes = excludes.map((d) => dayjs(d).format('YYYY-MM-DD')); + const normalizedIncludes = includes.map((d) => dayjs(d).format('YYYY-MM-DD')); const excludeRanges = []; let range = null; let d = dayjs(minTime); while (d.valueOf() <= maxTime) { - if (diagObj.db.isInvalidDate(d, dateFormat, excludes, includes)) { + const dStr = d.format('YYYY-MM-DD'); + if (normalizedExcludes.includes(dStr) && !normalizedIncludes.includes(dStr)) { if (!range) { range = { start: d, @@ -581,17 +583,11 @@ export const draw = function (text, id, version, diagObj) { rectangles .append('rect') - .attr('id', function (d) { - return 'exclude-' + d.start.format('YYYY-MM-DD'); - }) - .attr('x', function (d) { - return timeScale(d.start) + theSidePad; - }) + .attr('id', (d) => 'exclude-' + d.start.format('YYYY-MM-DD')) + .attr('x', (d) => timeScale(d.start.startOf('day')) + theSidePad) .attr('y', conf.gridLineStartPadding) - .attr('width', function (d) { - const renderEnd = d.end.add(1, 'day'); - return timeScale(renderEnd) - timeScale(d.start); - }) + .attr('width', (d) => timeScale(d.end.endOf('day')) - timeScale(d.start.startOf('day'))) + .attr('height', h - theTopPad - conf.gridLineStartPadding) .attr('transform-origin', function (d, i) { return (