mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-03 23:56:44 +02:00
Supports duration in decimal
This commit is contained in:
@@ -175,7 +175,7 @@ describe('Gantt diagram', () => {
|
|||||||
Another task :after a1, 20ms
|
Another task :after a1, 20ms
|
||||||
section Another
|
section Another
|
||||||
Another another task :b1, 20, 12ms
|
Another another task :b1, 20, 12ms
|
||||||
Another another another task :after b1, 24ms
|
Another another another task :after b1, 0.024s
|
||||||
`,
|
`,
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
@@ -238,7 +238,7 @@ const getStartDate = function (prevTime, dateFormat, str) {
|
|||||||
* @returns The date of the end of the duration.
|
* @returns The date of the end of the duration.
|
||||||
*/
|
*/
|
||||||
const parseDuration = function (durationStr, relativeTime) {
|
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) {
|
if (durationStatement !== null) {
|
||||||
switch (durationStatement[2]) {
|
switch (durationStatement[2]) {
|
||||||
case 'ms':
|
case 'ms':
|
||||||
|
@@ -8,11 +8,13 @@ describe('when using the ganttDb', function () {
|
|||||||
|
|
||||||
describe('when using relative times', function () {
|
describe('when using relative times', function () {
|
||||||
it.each`
|
it.each`
|
||||||
diff | date | expected
|
diff | date | expected
|
||||||
${'1d'} | ${moment('2019-01-01')} | ${moment('2019-01-02').toDate()}
|
${'1d'} | ${moment.utc('2019-01-01')} | ${'2019-01-02T00:00:00.000Z'}
|
||||||
${'1w'} | ${moment('2019-01-01')} | ${moment('2019-01-08').toDate()}
|
${'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 }) => {
|
`('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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user