mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-12-08 13:34:33 +01:00
resolve PR comments
This commit is contained in:
@@ -661,6 +661,35 @@ describe('Gantt diagram', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should render a gantt diagram excluding saturday and sunday in YYYY-MM-DD HH:mm:ss format', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
gantt
|
||||||
|
dateFormat YYYY-MM-DD HH:mm:ss
|
||||||
|
excludes weekends
|
||||||
|
weekend saturday
|
||||||
|
section Section
|
||||||
|
A task :a1, 2025-07-04 20:30:30, 2025-07-08 10:30:30
|
||||||
|
Another task:after a1, 20h
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('should render a gantt diagram excluding friday and saturday in YYYY-MM-DD HH:mm:ss format', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
gantt
|
||||||
|
dateFormat YYYY-MM-DD HH:mm:ss
|
||||||
|
excludes weekends
|
||||||
|
weekend friday
|
||||||
|
section Section
|
||||||
|
A task :a1, 2025-07-04 20:30:30, 2025-07-08 10:30:30
|
||||||
|
Another task:after a1, 20h
|
||||||
|
`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("should render when there's a semicolon in the title", () => {
|
it("should render when there's a semicolon in the title", () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -167,7 +167,10 @@ export const getTasks = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const isInvalidDate = function (date, dateFormat, excludes, includes) {
|
export const isInvalidDate = function (date, dateFormat, excludes, includes) {
|
||||||
if (includes.includes(date.format(dateFormat.trim()))) {
|
const formattedDate = date.format(dateFormat.trim());
|
||||||
|
const dateOnly = date.format('YYYY-MM-DD');
|
||||||
|
|
||||||
|
if (includes.includes(formattedDate) || includes.includes(dateOnly)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
@@ -180,7 +183,7 @@ export const isInvalidDate = function (date, dateFormat, excludes, includes) {
|
|||||||
if (excludes.includes(date.format('dddd').toLowerCase())) {
|
if (excludes.includes(date.format('dddd').toLowerCase())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return excludes.includes(date.format(dateFormat.trim()));
|
return excludes.includes(formattedDate) || excludes.includes(dateOnly);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const setWeekday = function (txt) {
|
export const setWeekday = function (txt) {
|
||||||
|
|||||||
@@ -554,14 +554,12 @@ export const draw = function (text, id, version, diagObj) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalizedExcludes = excludes.map((d) => dayjs(d).format('YYYY-MM-DD'));
|
const dateFormat = diagObj.db.getDateFormat();
|
||||||
const normalizedIncludes = includes.map((d) => dayjs(d).format('YYYY-MM-DD'));
|
|
||||||
const excludeRanges = [];
|
const excludeRanges = [];
|
||||||
let range = null;
|
let range = null;
|
||||||
let d = dayjs(minTime);
|
let d = dayjs(minTime);
|
||||||
while (d.valueOf() <= maxTime) {
|
while (d.valueOf() <= maxTime) {
|
||||||
const dStr = d.format('YYYY-MM-DD');
|
if (diagObj.db.isInvalidDate(d, dateFormat, excludes, includes)) {
|
||||||
if (normalizedExcludes.includes(dStr) && !normalizedIncludes.includes(dStr)) {
|
|
||||||
if (!range) {
|
if (!range) {
|
||||||
range = {
|
range = {
|
||||||
start: d,
|
start: d,
|
||||||
|
|||||||
Reference in New Issue
Block a user