Skip to content

Commit

Permalink
fix: set 'YYYY-MM-DD' as gantt default date format for mermaid-js#5862
Browse files Browse the repository at this point in the history
  • Loading branch information
good-jinu committed Jan 2, 2025
1 parent df636c6 commit b487f68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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 handle "YYYY-MM-DD" as default dateFormat', 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');
});
});

0 comments on commit b487f68

Please # to comment.