-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added exclude weekdays to definition #792
Conversation
Pull Request Test Coverage Report for Build 738
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great that you took it on you to tackle this. I still see some points of discussion though.
-
It's debatable what days are considered weekend throughout the world. Big parts of the world consider Friday and Saturday to be the weekend. So I propose to just explicitly state the weekdays you want to have excluded. So either "Saturday, Sunday" or "Friday, Saturday". This also leaves open the option for having a parttime working week where one would work 3 or 4 days a week.
-
This code currently seems to not take into account excluded days or dates that fall in the middle of durations. If I have a duration of 20d's I expect the Gantt chart to adjust for every excluded day within that period. Now it only seems to look at the exact end date of that duration.
-
If explicit end dates are given in the task definition, I don't think we should change that date if it's an excluded day or date. We should assume that the author had a valid reason for having that specific date. This is debatable, but that's what I'd would expect as behavior of the Gantt chart.
src/diagrams/gantt/ganttDb.js
Outdated
} | ||
// Default date - now | ||
return d.toDate() | ||
return getNextValidDate(d, dateFormat, excludes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand this correctly, this only checks whether an end date should be excluded, and if so, it returns the next Valid Date. But excluded dates can also fall in the duration of the task itself, and the duration should be adjusted accordingly. E.g. when you are excluding weekends, and the startdate is on a Friday, this function will return Tuesday as the enddate. But that's incorrect, it should return Thursday as the enddate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It was incorrect. My fix was to target the task after the start and end computation. See below.
src/diagrams/gantt/ganttDb.js
Outdated
return moment(str, dateFormat.trim(), true).toDate() | ||
let mDate = moment(str, dateFormat.trim(), true) | ||
if (mDate.isValid()) { | ||
return getNextValidDate(mDate, dateFormat, excludes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an explicit enddate is set, I'm not sure whether we should change the enddate based on exclusion of weekends or other dates. You could have an explicit enddate in the weekend, because of particular reasons for that task.
The bigger question is, should enddates only be adjusted based on exclusions, when the tasks defines a duration instead of a specific enddate? I would think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that, when the user wants an endTime, it is not necessary to skip weekend. So, my fix is to prevent this from happening.
But, I do not know if it was the best way to check if the endTime was manually inputted.
@@ -58,7 +63,22 @@ export const getTasks = function () { | |||
return tasks | |||
} | |||
|
|||
const getStartDate = function (prevTime, dateFormat, str) { | |||
const isInvalidDate = function (date, dateFormat, excludes) { | |||
if (date.isoWeekday() >= 6 && excludes.indexOf('weekends') >= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everywhere it says weekdays, (even in the PR title) but the code only checks for the word 'weekends'. The latter seems more logical, because people are more likely to wanting to exclude weekends. Although that has problems attached to it as well, which I will address in the general review comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. I kept weekend as the "default" but if the user chooses to put the weekday name (friday, saturday, monday), it will work too.
ganttDb.setDateFormat('YYYY-MM-DD') | ||
ganttDb.setExcludes('weekends 2019-02-06') | ||
ganttDb.addSection('testa1') | ||
ganttDb.addTask('test1', 'id1,2019-02-01,1d') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this would be:
ganttDb.addTask('test1', 'id1,2019-02-01,8d')
You'd expect
expect(tasks[1].startTime).toEqual(moment('2019-02-13', 'YYYY-MM-DD').toDate())
And your code would return 2019-01-11
Some more fringe test cases are needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added more tests.
The main reasoning now is:
I think it might be enough. Thank you for your observations and feedback. It is long due for me to give back to the community. Im eager to learn more about it. |
Shouldn't you check if the starttime itself isn't an excluded day or date? If a task ends on Friday, the following task should start on Monday, right? The end date should remain the same, since you already correct the enddate for the Saturday and the Sunday (if the weekend is excluded) but it just seems weird to have a task starting on a day that is excluded. |
Hum... true. It works this way, but its weird. I'll take a look on this. |
What are the chances this can be merged? Would love to get this feature upstream into all the VSCode plugins and such. |
If it works the chances are good! |
Amazing! |
…yarn/develop/mermaid-9.1.1 chore(deps): bump mermaid from 9.0.1 to 9.1.1
Added: exclude weekdays [and a list of specific dates] on Gantt.
As mentioned on issue #314
It is open to discussion how to render this:
But I think it can be handled on another issue if anyone needs it.