Standalone Work Timer
This workflow enables a timer that tracks the amount of time spent working on an issue.
File Name | jetbrains-youtrack-standaloneWorkTimer |
---|---|
Auto-attached | no |
Rules | Start timer: switch to 'Start' (stateless) |
To enable this workflow:
Enable and configure time tracking for your project.
Add an enumerated field with the name Timer to your project. Add the values Start and Stop to the field.
Add a date-type field with the name Timer time to your project.
Attach the Work Timer workflow to your project.
Use Case
This workflow enables a timer that you can use to track the amount of time you spend working on an issue. When you stop the timer, the elapsed time is automatically added to the issue as a work item.
Rules
This workflow includes two rules.
Start timer: switch to 'Start'
The first rule starts the timer.
rule Start timer: switch to 'Start'
when Timer.becomes({Start}) {
Timer time = now;
message(l10n ( The timer is started. ));
}
The second rule stops the timer. The elapsed time is added to the issue as a work item.
Stop timer: switch to 'Stop'
rule Stop timer: switch to 'Stop'
when Timer.becomes({Stop}) {
if (Timer.oldValue == {Start}) {
var duration = now - Timer time;
var seconds = (duration.millis - duration.millis % 1000) / 1000;
var minutes = (seconds - seconds % 60) / 60;
var hours = (minutes - minutes % 60) / 60;
var days = (hours - hours % 24) / 24;
minutes = minutes % 60;
hours = hours % 24;
if (days !=0) {
message(l10n ( Work time: {days} day(s) {hours} hour(s) {minutes} minute(s). ));
} else if (hours!=0) {
message(l10n ( Work time: {hours} hour(s) {minutes} minute(s). ));
} else {
message(l10n ( Work time: {minutes} minute(s). ));
}
issue.applyCommand(l10n ( add work Today {days + " "} d {hours + " "} h {minutes + " "} m )
+ " " + l10n ( The work item automatically added by the timer. ));
} else {
message(l10n ( Looks like the timer hasn't been started. ));
}
}