Dates, Durations
Date and durations help to deal with date related business logic.

Durations

A duration value may be defined with a combination of several duration units:
  • second with s
  • minute with m
  • hour with h
  • day with d
  • week with w
Duration values are integers, positive, or negative.
1
effect {
2
var d1 = 4d; // 4 days
3
var d2 = 1w; // 1 week
4
var d3 = 2d10h; // 2 days and 10 hours
5
var d4 = -5d; // minus 5 days
6
}
Copied!
Durations values may be compared with the 6 comparison operators = < > <= >= <>.
Two duration values may be added or subtracted. It is also possible to multiply a duration by an integer value.
1
effect {
2
var d1 = 55w; // 55 weeks
3
var d2 = 3d; // 3 days
4
var d3 = d1 + d2 // equal to '55w3d'
5
var d2 = 10 * d3 // 555 weeks
6
}
Copied!

Dates

Date format is ISO 8601.
1
constant date0 : date = 2019-01-01
2
constant date1 : date = 2019-01-01T01:02:03
3
constant date2 : date = 2019-01-01T01:02:03Z
4
constant date3 : date = 2019-01-01T00:00:00+01:00
5
constant date4 : date = 2019-01-01T00:00:00-05:30
Copied!
The subtraction of two dates returns a duration; since the duration is a positive number, if d1 and d2 are two dates, then d1 - d2 = d2 - d2 >= 0 holds.
1
effect {
2
var d1 := 2020-06-28;
3
var d2 := 2020-05-28;
4
if (d1 - d2 = 4w) then transfer 1tz to coder;
5
}
Copied!
It is possible to add or subtract a duration to a date value to get a new date.
1
effect {
2
var d1 := 2020-06-17;
3
if (d1 + 5d = 2020-06-22) then transfer 1tz to coder;
4
}
Copied!

Now

now is the keyword to refer to the date at execution.
1
variable deadline : date = 2020-09-01
2
3
action submit() {
4
require {
5
r1 : deadline - 8w <= now <= dealine + 1d
6
}
7
effect {
8
...
9
}
10
}
Copied!
Last modified 8mo ago
Export as PDF
Copy link
Edit on GitHub