From 3315ae838263ff767fd731cede947bfaca536d2d Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Wed, 24 Aug 2022 23:50:42 +0200 Subject: [PATCH] Supports duration in decimal --- cypress/integration/rendering/gantt.spec.js | 2 +- src/diagrams/gantt/ganttDb.js | 2 +- src/diagrams/gantt/ganttDb.spec.js | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cypress/integration/rendering/gantt.spec.js b/cypress/integration/rendering/gantt.spec.js index 7dc7c6cf5..e6c79a717 100644 --- a/cypress/integration/rendering/gantt.spec.js +++ b/cypress/integration/rendering/gantt.spec.js @@ -175,7 +175,7 @@ describe('Gantt diagram', () => { Another task :after a1, 20ms section Another Another another task :b1, 20, 12ms - Another another another task :after b1, 24ms + Another another another task :after b1, 0.024s `, {} ); diff --git a/src/diagrams/gantt/ganttDb.js b/src/diagrams/gantt/ganttDb.js index e8c75a982..996f22e79 100644 --- a/src/diagrams/gantt/ganttDb.js +++ b/src/diagrams/gantt/ganttDb.js @@ -238,7 +238,7 @@ const getStartDate = function (prevTime, dateFormat, str) { * @returns The date of the end of the duration. */ const parseDuration = function (durationStr, relativeTime) { - const durationStatement = /^([\d]+)([wdhms]|ms)$/.exec(durationStr.trim()); + const durationStatement = /^(\d+(?:\.\d+)?)([wdhms]|ms)$/.exec(durationStr.trim()); if (durationStatement !== null) { switch (durationStatement[2]) { case 'ms': diff --git a/src/diagrams/gantt/ganttDb.spec.js b/src/diagrams/gantt/ganttDb.spec.js index 1d2b3724f..e3622a5fb 100644 --- a/src/diagrams/gantt/ganttDb.spec.js +++ b/src/diagrams/gantt/ganttDb.spec.js @@ -8,11 +8,13 @@ describe('when using the ganttDb', function () { describe('when using relative times', function () { it.each` - diff | date | expected - ${'1d'} | ${moment('2019-01-01')} | ${moment('2019-01-02').toDate()} - ${'1w'} | ${moment('2019-01-01')} | ${moment('2019-01-08').toDate()} + diff | date | expected + ${'1d'} | ${moment.utc('2019-01-01')} | ${'2019-01-02T00:00:00.000Z'} + ${'1w'} | ${moment.utc('2019-01-01')} | ${'2019-01-08T00:00:00.000Z'} + ${'1ms'} | ${moment.utc('2019-01-01')} | ${'2019-01-01T00:00:00.001Z'} + ${'0.1s'} | ${moment.utc('2019-01-01')} | ${'2019-01-01T00:00:00.100Z'} `('should add $diff to $date resulting in $expected', ({ diff, date, expected }) => { - expect(ganttDb.parseDuration(diff, date)).toEqual(expected); + expect(ganttDb.parseDuration(diff, date).toISOString()).toEqual(expected); }); });