From 525a7de8ae7983a6d0e3b8cc299d524147d25abb Mon Sep 17 00:00:00 2001 From: darshanr0107 Date: Mon, 15 Sep 2025 12:12:47 +0530 Subject: [PATCH] fix:gant chart crashing in browser on-behalf-of: @Mermaid-Chart --- cypress/integration/rendering/gantt.spec.js | 30 +++++++++++++++++++ .../mermaid/src/diagrams/gantt/ganttDb.js | 4 ++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/cypress/integration/rendering/gantt.spec.js b/cypress/integration/rendering/gantt.spec.js index 32dbcb4d9..72cb6ea29 100644 --- a/cypress/integration/rendering/gantt.spec.js +++ b/cypress/integration/rendering/gantt.spec.js @@ -803,4 +803,34 @@ describe('Gantt diagram', () => { {} ); }); + it('should handle numeric timestamps with dateFormat x', () => { + imgSnapshotTest( + ` + gantt + title Process time profile (ms) + dateFormat x + axisFormat %L + tickInterval 250millisecond + + section Pipeline + Parse JSON p1: 000, 120 + `, + {} + ); + }); + it('should handle numeric timestamps with dateFormat X', () => { + imgSnapshotTest( + ` + gantt + title Process time profile (ms) + dateFormat X + axisFormat %L + tickInterval 250millisecond + + section Pipeline + Parse JSON p1: 000, 120 + `, + {} + ); + }); }); diff --git a/packages/mermaid/src/diagrams/gantt/ganttDb.js b/packages/mermaid/src/diagrams/gantt/ganttDb.js index b2b5b0566..b1b2052c1 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDb.js +++ b/packages/mermaid/src/diagrams/gantt/ganttDb.js @@ -268,7 +268,9 @@ const fixTaskDates = function (startTime, endTime, dateFormat, excludes, include const getStartDate = function (prevTime, dateFormat, str) { str = str.trim(); - + if ((dateFormat.trim() === 'x' || dateFormat.trim() === 'X') && /^\d+$/.test(str)) { + return new Date(Number(str)); + } // Test for after const afterRePattern = /^after\s+(?[\d\w- ]+)/; const afterStatement = afterRePattern.exec(str);