mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-15 06:19:24 +02:00
Merge pull request #6734 from mermaid-js/6730-gantt-excludes-datetime-format
6730: Fix excluded dates ignored in YYYY-MM-DD HH:mm:ss date format in gantt diagram
This commit is contained in:
5
.changeset/fuzzy-pears-cough.md
Normal file
5
.changeset/fuzzy-pears-cough.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'mermaid': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: handle exclude dates properly in Gantt charts when using dateFormat: 'YYYY-MM-DD HH:mm:ss'
|
@@ -647,6 +647,49 @@ describe('Gantt diagram', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should render a gantt diagram excluding a specific date in YYYY-MM-DD HH:mm:ss format', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
gantt
|
||||||
|
dateFormat YYYY-MM-DD HH:mm:ss
|
||||||
|
excludes 2025-07-07
|
||||||
|
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 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) {
|
||||||
|
@@ -581,17 +581,11 @@ export const draw = function (text, id, version, diagObj) {
|
|||||||
|
|
||||||
rectangles
|
rectangles
|
||||||
.append('rect')
|
.append('rect')
|
||||||
.attr('id', function (d) {
|
.attr('id', (d) => 'exclude-' + d.start.format('YYYY-MM-DD'))
|
||||||
return 'exclude-' + d.start.format('YYYY-MM-DD');
|
.attr('x', (d) => timeScale(d.start.startOf('day')) + theSidePad)
|
||||||
})
|
|
||||||
.attr('x', function (d) {
|
|
||||||
return timeScale(d.start) + theSidePad;
|
|
||||||
})
|
|
||||||
.attr('y', conf.gridLineStartPadding)
|
.attr('y', conf.gridLineStartPadding)
|
||||||
.attr('width', function (d) {
|
.attr('width', (d) => timeScale(d.end.endOf('day')) - timeScale(d.start.startOf('day')))
|
||||||
const renderEnd = d.end.add(1, 'day');
|
|
||||||
return timeScale(renderEnd) - timeScale(d.start);
|
|
||||||
})
|
|
||||||
.attr('height', h - theTopPad - conf.gridLineStartPadding)
|
.attr('height', h - theTopPad - conf.gridLineStartPadding)
|
||||||
.attr('transform-origin', function (d, i) {
|
.attr('transform-origin', function (d, i) {
|
||||||
return (
|
return (
|
||||||
|
Reference in New Issue
Block a user