-
Notifications
You must be signed in to change notification settings - Fork 227
proposal 185
This is a fix for Issue 185.
The current duration(string)
function accepts a floating point value with a s
suffix indicating a duration in seconds which is at parity with what the protobuf
utilities support for parsing google.protobuf.Duration
values from strings;
however, this format is incredibly difficult to use in practice.
A more human-readable format like the one supported by golang time.ParseDuration
would vastly improve the usability of duration(string)
, so we propose to update
the spec to include ns, us, ms, s, m, h
durations with a mix of duration intervals
in the same literal.
The golang time.ParseDuration
method supports an easy to read duration string
as input:
Examples:
0
1h2m3.4s
+2.999999999us
-24h
Grammar:
duration: sign? (0 | (leading_digit digit* ('.' digit+)? unit)+)
sign: ('+' | '-')
leading_digit: 1..9
digit: 0 | leading_digit
unit: ('ns' | 'us' | 'ms' | 's' | 'm' | 'h')
This functionality is also available in the abseil.io C++ libraries as
time::ParseDuration
.
Go and C++ support inf
as an input, but as the input is not a valid
google.protobuf.Duration
value, infinite duration values should not be
accepted in CEL. Likewise, the valid duration range will be limited to the
duration values which can be supported by the
google.protobuf.Duration
Duration units are neither required to appear in order, e.g. 2m1h
is valid,
nor required to be non-overlapping / non-repeating. The spec is flexible in
these regards as they are better left as best practices.