Reputation: 753
I would like a certain schedule rule (with notifications) to be executed only during work days. I.e. I would like to avoid receiving notifications on Saturdays and Sundays. How can I check for a current day of the week in YouTrack Workflow?
Upvotes: 3
Views: 1245
Reputation: 11
Probably the shortest solution specifically for avoiding weekends, as Saturday and Sunday are the only days beginning with an uppercase 'S':
if(!now.format(#E).startsWith("S", opts)) {}
/e: as Artem correctly pointed out, this may have to be adopted or does not work for certain localizations - it does at least for German and English.
Upvotes: 0
Reputation: 2700
I faced the same issue, I didn't find the previous solutions readable. The solution I've implemented:
var today = now.format(utc).substring(0, 3);
if (today == "Mon" || today == "Tue" || today == "Wed" || today == "Thu" || today == "Fri") {
message("Work day!");
}
Upvotes: 2
Reputation: 41
Using format you can get day of week abbreviation or full name.
var dayOfWeekAbr = now.format(#E);
var dayOfWeek = now.format(#EEEE);
Or using year-month-day literal (2014-01-05 was Sunday):
var day = (created - 2014-01-05).millis / 86400000 % 7;
if (day > 1 && day < 6) {
message("Work day");
}
Upvotes: 3
Reputation: 21
There isn't built-in YouTrack workflow mechanism of defining a current day of week, but the simple workaround allows to do it:
schedule rule day of week
daily at 10:00:00 [for all issues] {
var monday = {issue: A-1}.created - 1 day;
while (i < 50) {
if (monday + (i * 7) days < now && now < monday + (i * 7 + 5) days) {
//now is the work day
}
}
The issue A-1
is a sample issue created on Tuesday, so {issue: A-1}.created - 1 day
refers to the Monday
.
The while
cycle finds the current week and if()
defines whether today is a work day or a weekend.
Upvotes: 2