Skip to content

proposal 175

Jim Larson edited this page Feb 18, 2021 · 2 revisions

This is a fix for Issue 175.

The current Duration.get*() functions are inconsistent with each other and with the Timestamp.get*() functions. The Timestamp.get*() functions extract the named part of the date-time, e.g. timestamp('2009-02-13T23:31:30Z').getMinutes() returns 31. The Duration.get*() functions mostly convert the duration into the named units, e.g. duration('3730s').getMinutes() returns 62. The exception is the Duration.getMilliseconds() function which:

  • is documented as returning the milliseconds component in a range 0-999;
  • has a conformance test that requires conversion to milliseconds of total duration;
  • follows the conformance tests for the cel-go implementation, but the spec for the other implementations.

The use of the same name for functions with different semantics is undesirable.

We believe that there are more stored expressions in the wild that might rely on the conversion behavior than the extraction behavior.

There doesn't seem to be a need for extracting unit components from a duration, nor for getting units-since-epoch for a timestamp.

The proposal is:

  1. Create a new set of int-valued methods Duration.to*(), with the more explicit name better describing the conversion semantics.
  2. Mark the Duration.get*() functions as deprecated.
  3. Update the conformance tests for Duration.getMilliseconds() to test that it extracts the millisecond component, as documented.
  4. Update cel-go to match the spec, possibly with a flag for the old behavior if requested.
Clone this wiki locally