Supports duration in decimal

This commit is contained in:
Valentin Valls 2022-08-24 23:50:42 +02:00
parent f7b8d1ac07
commit 3315ae8382
3 changed files with 8 additions and 6 deletions

View File

@ -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
`,
{}
);

View File

@ -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':

View File

@ -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);
});
});