Skip to content

Commit

Permalink
Merge pull request #3355 from vallsv/feature-ms-duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash-Singh1 committed Aug 24, 2022
2 parents 49eebc1 + 0583c4f commit cde3a7c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
18 changes: 18 additions & 0 deletions cypress/integration/rendering/gantt.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ describe('Gantt diagram', () => {
);
});

it('should handle milliseconds', () => {
imgSnapshotTest(
`
gantt
title A Gantt Diagram
dateFormat x
axisFormat %L
section Section
A task :a1, 0, 30ms
Another task :after a1, 20ms
section Another
Another another task :b1, 20, 12ms
Another another another task :after b1, 24ms
`,
{}
);
});

it('should render a gantt diagram when useMaxWidth is true (default)', () => {
renderGraph(
`
Expand Down
5 changes: 4 additions & 1 deletion src/diagrams/gantt/ganttDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ const getStartDate = function (prevTime, dateFormat, str) {
const durationToDate = function (durationStatement, relativeTime) {
if (durationStatement !== null) {
switch (durationStatement[2]) {
case 'ms':
relativeTime.add(durationStatement[1], 'milliseconds');
break;
case 's':
relativeTime.add(durationStatement[1], 'seconds');
break;
Expand Down Expand Up @@ -267,7 +270,7 @@ const getEndDate = function (prevTime, dateFormat, str, inclusive) {
return mDate.toDate();
}

return durationToDate(/^([\d]+)([wdhms])/.exec(str.trim()), moment(prevTime));
return durationToDate(/^([\d]+)([wdhms]|ms)$/.exec(str.trim()), moment(prevTime));
};

let taskCnt = 0;
Expand Down
21 changes: 21 additions & 0 deletions src/diagrams/gantt/ganttDb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ describe('when using the ganttDb', function () {
}
);

it('should handle milliseconds', function () {
ganttDb.setDateFormat('x');
ganttDb.addSection('testa1');
ganttDb.addTask('test1', 'id1,0,20ms');
ganttDb.addTask('test2', 'id2,after id1,5ms');
ganttDb.addSection('testa2');
ganttDb.addTask('test3', 'id3,20,10ms');
ganttDb.addTask('test4', 'id4,after id3,5ms');

const tasks = ganttDb.getTasks();

expect(tasks[0].startTime.toISOString()).toEqual('1970-01-01T00:00:00.000Z');
expect(tasks[0].endTime.toISOString()).toEqual('1970-01-01T00:00:00.020Z');
expect(tasks[1].startTime.toISOString()).toEqual('1970-01-01T00:00:00.020Z');
expect(tasks[1].endTime.toISOString()).toEqual('1970-01-01T00:00:00.025Z');
expect(tasks[2].startTime.toISOString()).toEqual('1970-01-01T00:00:00.020Z');
expect(tasks[2].endTime.toISOString()).toEqual('1970-01-01T00:00:00.030Z');
expect(tasks[3].startTime.toISOString()).toEqual('1970-01-01T00:00:00.030Z');
expect(tasks[3].endTime.toISOString()).toEqual('1970-01-01T00:00:00.035Z');
});

it('should handle relative start date based on id regardless of sections', function () {
ganttDb.setDateFormat('YYYY-MM-DD');
ganttDb.addSection('testa1');
Expand Down

0 comments on commit cde3a7c

Please sign in to comment.