Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 'YYYY-MM-DD' as gantt default date format #6163

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/perfect-jars-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mermaid': patch
---

fix: Set 'YYYY-MM-DD' as gantt default date format
4 changes: 2 additions & 2 deletions packages/mermaid/src/diagrams/gantt/ganttDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dayjs.extend(dayjsCustomParseFormat);
dayjs.extend(dayjsAdvancedFormat);

const WEEKEND_START_DAY = { friday: 5, saturday: 6 };
let dateFormat = '';
let dateFormat = 'YYYY-MM-DD';
let axisFormat = '';
let tickInterval = undefined;
let todayMarker = '';
Expand Down Expand Up @@ -52,7 +52,7 @@ export const clear = function () {
lastTask = undefined;
lastTaskID = undefined;
rawTasks = [];
dateFormat = '';
dateFormat = 'YYYY-MM-DD';
axisFormat = '';
displayMode = '';
tickInterval = undefined;
Expand Down
19 changes: 18 additions & 1 deletion packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('when using the ganttDb', function () {
${'getTasks'} | ${[]}
${'getAccTitle'} | ${''}
${'getAccDescription'} | ${''}
${'getDateFormat'} | ${''}
${'getDateFormat'} | ${'YYYY-MM-DD'}
${'getAxisFormat'} | ${''}
${'getTodayMarker'} | ${''}
${'getExcludes'} | ${[]}
Expand Down Expand Up @@ -505,4 +505,21 @@ describe('when using the ganttDb', function () {
ganttDb.addTask('test1', 'id1,202304,1d');
expect(() => ganttDb.getTasks()).toThrowError('Invalid date:202304');
});

it('should parse date with default format YYYY-MM-DD', function () {
ganttDb.addTask('test1', 'id1,2025-01-01,2025-01-14');
ganttDb.addTask('test2', 'id2,after id1,2025-01-18');

const tasks = ganttDb.getTasks();

expect(tasks[0].startTime).toEqual(new Date(2025, 0, 1));
expect(tasks[0].endTime).toEqual(new Date(2025, 0, 14));
expect(tasks[0].id).toEqual('id1');
expect(tasks[0].task).toEqual('test1');

expect(tasks[1].startTime).toEqual(new Date(2025, 0, 14));
expect(tasks[1].endTime).toEqual(new Date(2025, 0, 18));
expect(tasks[1].id).toEqual('id2');
expect(tasks[1].task).toEqual('test2');
});
});
Loading