Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions doc/langdef.md
Original file line number Diff line number Diff line change
Expand Up @@ -2053,20 +2053,35 @@ double("3.14") // 3.14 (if successful, otherwise an error)

Type conversion for duration values.

Note, duration strings should support the following suffixes:

* "h" (hour)
* "m" (minute)
* "s" (second)
* "ms" (millisecond)
* "us" (microsecond)
* "ns" (nanosecond)

Duration strings may be zero (`"0"`), negative (`-1h`), fractional (`-23.4s`),
and/or compound (`1h34us`). Durations greater than the hour granularity, such
as days or weeks, are not supported as this would necessitate an understanding
of the locale of the execution context to account for leap seconds and leap
years.
Duration strings support decimal values with the following unit suffixes:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cel-go implementation is just using go's stdlib time.ParseDuration. For cel-cpp and cel-java, we use libraries that cite go as the format spec and reference implementation. so might make sense to to cite the godoc here?

fwiw abseil doesn't handle mu for microseconds so there are at least some inconsistencies for cel-cpp.

@TristonianJones thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so might make sense to to cite the godoc here

I don't think it has anything to offer. In my experience, Pike is nakedly hostile to tightly-specified behavior, and time.ParseDuration seems like no exception — if we want a spec, I think we have to own it here.


* `h` (hour)
* `m` (minute)
* `s` (second)
* `ms` (millisecond)
* `us` or `µs` (microsecond)
* `ns` (nanosecond)

Values are concatenated with their units without a space (`1s`). Values may
include a decimal point (`23.4s`) and can omit either the integer-part
(`.5m`) or fractional part (`30.s`). Fractional nanoseconds (`0.9ns`) are
silently truncated.

Multiple values may be concatenated (`1h34us`) in any order (`15m30s1h`) and
with any repetition (`1s1s1s`) to form a compound value that equals the sum of
its parts.

A zero-length duration may be represented as the unitless (`0`), but this
cannot be concatenated with any other value.

Any duration string may be prefixed with a minus sign (`-`) or an inert plus
sign (`+`), which applies to the duration value after it is computed (in the
case of compound values).

Duration units greater than the hour granularity, such as days or weeks, are not
supported as this would necessitate an understanding of the locale of the
execution context to account for daylight savings time, leap seconds, and
leap years.

**Signatures:**

Expand Down
Loading