mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
address review comment on implementation; apply similar changes on existing impl of keyword 'after'
This commit is contained in:
parent
b44ec7dadd
commit
099f580e52
@ -256,31 +256,25 @@ const getStartDate = function (prevTime, dateFormat, str) {
|
|||||||
str = str.trim();
|
str = str.trim();
|
||||||
|
|
||||||
// Test for after
|
// Test for after
|
||||||
const re = /^after\s+([\d\w- ]+)/;
|
const afterRePattern = /^after\s+(?<ids>[\d\w- ]+)/;
|
||||||
const afterStatement = re.exec(str.trim());
|
const afterStatement = afterRePattern.exec(str);
|
||||||
|
|
||||||
if (afterStatement !== null) {
|
if (afterStatement !== null) {
|
||||||
// check all after ids and take the latest
|
// check all after ids and take the latest
|
||||||
let latestEndingTask = null;
|
let latestTask = null;
|
||||||
afterStatement[1].split(' ').forEach(function (id) {
|
for (const id of afterStatement.groups.ids.split(' ')) {
|
||||||
let task = findTaskById(id);
|
let task = findTaskById(id);
|
||||||
if (task !== undefined) {
|
if (task !== undefined && (!latestTask || task.endTime > latestTask.endTime)) {
|
||||||
if (!latestEndingTask) {
|
latestTask = task;
|
||||||
latestEndingTask = task;
|
|
||||||
} else {
|
|
||||||
if (task.endTime > latestEndingTask.endTime) {
|
|
||||||
latestEndingTask = task;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!latestEndingTask) {
|
if (latestTask) {
|
||||||
const dt = new Date();
|
return latestTask.endTime;
|
||||||
dt.setHours(0, 0, 0, 0);
|
|
||||||
return dt;
|
|
||||||
} else {
|
} else {
|
||||||
return latestEndingTask.endTime;
|
const today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
return today;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,42 +337,36 @@ const parseDuration = function (str) {
|
|||||||
const getEndDate = function (prevTime, dateFormat, str, inclusive = false) {
|
const getEndDate = function (prevTime, dateFormat, str, inclusive = false) {
|
||||||
str = str.trim();
|
str = str.trim();
|
||||||
|
|
||||||
// Test for until
|
// test for until
|
||||||
const re = /^until\s+([\d\w- ]+)/;
|
const untilRePattern = /^until\s+(?<ids>[\d\w- ]+)/;
|
||||||
const untilStatement = re.exec(str.trim());
|
const untilStatement = untilRePattern.exec(str);
|
||||||
|
|
||||||
if (untilStatement !== null) {
|
if (untilStatement !== null) {
|
||||||
// check all until ids and take the earliest
|
// check all until ids and take the earliest
|
||||||
let earliestStartingTask = null;
|
let earliestTask = null;
|
||||||
untilStatement[1].split(' ').forEach(function (id) {
|
for (const id of untilStatement.groups.ids.split(' ')) {
|
||||||
let task = findTaskById(id);
|
let task = findTaskById(id);
|
||||||
if (task !== undefined) {
|
if (task !== undefined && (!earliestTask || task.startTime < earliestTask.startTime)) {
|
||||||
if (!earliestStartingTask) {
|
earliestTask = task;
|
||||||
earliestStartingTask = task;
|
|
||||||
} else {
|
|
||||||
if (task.startTime < earliestStartingTask.startTime) {
|
|
||||||
earliestStartingTask = task;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!earliestStartingTask) {
|
|
||||||
const dt = new Date();
|
|
||||||
dt.setHours(0, 0, 0, 0);
|
|
||||||
return dt;
|
|
||||||
} else {
|
|
||||||
return earliestStartingTask.startTime;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for actual date
|
if (earliestTask) {
|
||||||
let mDate = dayjs(str, dateFormat.trim(), true);
|
return earliestTask.startTime;
|
||||||
if (mDate.isValid()) {
|
} else {
|
||||||
|
const today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
return today;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for actual date
|
||||||
|
let parsedDate = dayjs(str, dateFormat.trim(), true);
|
||||||
|
if (parsedDate.isValid()) {
|
||||||
if (inclusive) {
|
if (inclusive) {
|
||||||
mDate = mDate.add(1, 'd');
|
parsedDate = parsedDate.add(1, 'd');
|
||||||
}
|
}
|
||||||
return mDate.toDate();
|
return parsedDate.toDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
let endTime = dayjs(prevTime);
|
let endTime = dayjs(prevTime);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user