Working with Dates and Times
When you write workflow rules, especially scheduled rules and scheduled transitions in state-machine rules, you use conditions that evaluate dates, periods, and durations. This time-related information can be referenced in the following contexts:
How Soon is Now?
When you write workflow rules that compare dates, take note of the actual times that are stored in each field, how they compare to date constants, and the value of the keyword now
.
- Dates that are stored in custom fields that are created in YouTrack are assigned a date value with the time as 12:00 UTC.
- If you set the value of a custom field outside of YouTrack, the field stores the actual time value that is assigned to the field. This includes values that are assigned to custom fields by a workflow, an integration with TeamCity (assembleDate), or by the REST API.
- Dates that are stored in issue fields are assigned a value that corresponds to the instant when the action took place in the time zone that is set for your YouTrack server.
- Scheduled rules run according to the server clock.
Let's take a look at the following example:
You want to notify users of issues that need to be resolved in the current working day. You write a rule that looks identifies issues by due date. You want to notify users before they arrive in the office, so you schedule the rule to run at 08:00. Your rule would look something like this:
schedule rule Check for Due date and notify assignee
daily at 08 : 00 : 00 [issue.Due date <= now] {
issue.Assignee.notify("Issue is due today", "Please resolve the following issue:" + issue.getId());
}
The schedule uses the date constant 08 : 00 : 00
, which uses the time zone setting for your YouTrack server.
The issue.Due date
references a custom field that stores the date and time as 12:00 UTC.
- If your office is in Seattle (UTC-7), the value of
now
at 08:00 is 15:00. The guard expression resolves to[<current date> 12:00:00 <= <current date> 15:00:00]
, which is true. You could use the rule as it is written. - If your office is in Sydney (UTC+10), the value of
now
at 08:00 is 22:00 for the previous day. The guard expression resolves to[<current date> 12:00:00 <= <previous date> 22:00:00]
, which is false.
To notify users of issues that are due today, you must offset one of the values. The modified guard expression would look something like this:[issue.Due date <= (now + 10 hours)]
. The due date for issues that are due today would exactly match the value that is returned by the expression.
Operators and Time-related Values
Arithmetic and relational operators can be used with dates, periods, and durations. The data type that is returned by the operator varies based on the combination of data types.