From 7b12c7a07db2a0196e0b69aacc86b2d32b33af70 Mon Sep 17 00:00:00 2001 From: Sophie Dankel Date: Tue, 24 Dec 2019 19:01:29 -0800 Subject: [PATCH] Fix infinite loop caused by date iteration --- cypress/integration/rendering/gantt.spec.js | 40 +++++++++++++++++++++ src/diagrams/gantt/ganttDb.js | 2 +- src/diagrams/gantt/ganttDb.spec.js | 20 +++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/cypress/integration/rendering/gantt.spec.js b/cypress/integration/rendering/gantt.spec.js index 027c893a7..5d9850f94 100644 --- a/cypress/integration/rendering/gantt.spec.js +++ b/cypress/integration/rendering/gantt.spec.js @@ -54,4 +54,44 @@ describe('Sequencediagram', () => { {} ); }); + it('should render a gantt chart for issue #1060', () => { + imgSnapshotTest( + ` + gantt + excludes weekdays 2017-01-10 + title Projects Timeline + + section asdf + specs :done, :ps, 2019-05-10, 50d + Plasma :pc, 2019-06-20, 60d + Rollup :or, 2019-08-20, 50d + + section CEL + + plasma-chamber :done, :pc, 2019-05-20, 60d + Plasma Implementation (Rust) :por, 2019-06-20, 120d + Predicates (Atomic Swap) :pred, 2019-07-20, 60d + + section DEX 💰 + + History zkSNARK :hs, 2019-08-10, 40d + Exit :vs, after hs, 60d + PredicateSpec :ps, 2019-09-1, 20d + PlasmaIntegration :pi, after ps,40d + + + section Events 🏁 + + ETHBoston :done, :eb, 2019-09-08, 3d + DevCon :active, :dc, 2019-10-08, 3d + + section Plasma Calls & updates ✨ + OVM :ovm, 2019-07-12, 120d + Plasma call 26 :pc26, 2019-08-21, 1d + Plasma call 27 :pc27, 2019-09-03, 1d + Plasma call 28 :pc28, 2019-09-17, 1d + `, + {} + ); + }); }); diff --git a/src/diagrams/gantt/ganttDb.js b/src/diagrams/gantt/ganttDb.js index c5b266414..6eae11449 100644 --- a/src/diagrams/gantt/ganttDb.js +++ b/src/diagrams/gantt/ganttDb.js @@ -117,7 +117,7 @@ const checkTaskDates = function(task, dateFormat, excludes) { const fixTaskDates = function(startTime, endTime, dateFormat, excludes) { let invalid = false; let renderEndTime = null; - while (startTime.date() <= endTime.date()) { + while (startTime <= endTime) { if (!invalid) { renderEndTime = endTime.toDate(); } diff --git a/src/diagrams/gantt/ganttDb.spec.js b/src/diagrams/gantt/ganttDb.spec.js index 433e3a495..547122685 100644 --- a/src/diagrams/gantt/ganttDb.spec.js +++ b/src/diagrams/gantt/ganttDb.spec.js @@ -174,6 +174,26 @@ describe('when using the ganttDb', function() { expect(tasks[6].task).toEqual('test7'); }); + it('should work when end date is the 31st', function() { + ganttDb.setDateFormat('YYYY-MM-DD'); + ganttDb.addSection('Task endTime is on the 31st day of the month'); + ganttDb.addTask('test1', 'id1,2019-09-30,11d'); + ganttDb.addTask('test2', 'id2,after id1,20d'); + const tasks = ganttDb.getTasks(); + + expect(tasks[0].startTime).toEqual(moment('2019-09-30', 'YYYY-MM-DD').toDate()); + expect(tasks[0].endTime).toEqual(moment('2019-10-11', 'YYYY-MM-DD').toDate()); + expect(tasks[1].renderEndTime).toBeNull(); // Fixed end + expect(tasks[0].id).toEqual('id1'); + expect(tasks[0].task).toEqual('test1'); + + expect(tasks[1].startTime).toEqual(moment('2019-10-11', 'YYYY-MM-DD').toDate()); + expect(tasks[1].endTime).toEqual(moment('2019-10-31', 'YYYY-MM-DD').toDate()); + expect(tasks[1].renderEndTime).toBeNull(); // Fixed end + expect(tasks[1].id).toEqual('id2'); + expect(tasks[1].task).toEqual('test2'); + }); + describe('when setting inclusive end dates', function() { beforeEach(function() { ganttDb.setDateFormat('YYYY-MM-DD');