How can one subtract and compare dates inside the workflow editor
Hello,
I want to set a certain tag on an issue as soon as the due date is within 3 days or less.
So, I want to schedule a task that runs every day and looks if ...
- the issue is between 3 or 2 days from the due date. Then I want to add a tag "Due date will be reached in 3 days"
- the issue is between 2 or 1 days from the due date. Then I want to add a tag "Due date will be reached in 2 days"
- the issue is between 0 or 1 days from the due date. Then I want to add a tag "Due date will be reached in 1 days"
- the issue is smaller then 0 days. Then I want to add a tag "Due date has passed"
I found that you can request the current date with "now". But how can i find out how many days are left untill the due date?
Thanks
Jeroen
Please sign in to leave a comment.
Dear Jeroen,
You can try following code:
schedule rule Subtract and compare dates inside the workflow editor
daily at 12 : 0 : 0 [!issue.State.isResolved] {
if (now + 3 days < Due Date) {
// Do nothing
} else if (now + 2 days < Due Date) {
issue.addTag("Due date will be reached in 3 days");
} else if (now + 1 day < Due Date) {
issue.addTag("Due date will be reached in 2 days");
} else if (now < Due Date) {
issue.addTag("Due date will be reached in 1 days");
} else {
issue.addTag("Due date has passed");
}
}
I've attached the sample. You can import it to either workflow editor or YouTrack.
Attachment(s):
due-date-will-be-reached.zip
Thank you Maxim. I will give it a go :-)