-
Notifications
You must be signed in to change notification settings - Fork 271
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).
The golang time.ParseDuration method supports an easy to read duration string
as input:
Examples:
0
1h2m3..4s
+2.999999999us
-24h
Grammer:
duration: sign? (0 | (digit ('.' digit)? unit)+)
sign: ('+' | '-')
digit: 0..9+
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
Feedback from jimlarson:
- "Grammar"
- Second example doesn't match grammar - should it be
1h2m3.4s? - Not the usual numeric syntax: allows
007s, consider(0|[1-9][0-9]*)(.[0-9]+)?for numbers. - Allows oddities, need to specify the semantics:
- Arbitrary order:
15m4h3s - Repeats:
3s13s7s - Fractional things which aren't usually fractions:
0.8h - Fractional parts of one unit can overlap with other units:
2.0047h4.009s12.4853ms43.9247us. - Consider requiring order of descending scale, no repeats, ditch fraction except perhaps
3672.432swith no other components.
- Arbitrary order: