CH06-L02 · applied

Comparing time values

Check whether a received event met its deadline.

General CELRuns hereDocumented
What will I learn?

You can compare normalized time values instead of relying on fragile text comparison.

Where will I try it?

Directly below, in the browser playground.

What do I do?

Run both modes, compare where their values come from, then complete the task.

Try CEL · browser pilot

Try both ways to supply values

Define local values inside one CEL expression, or provide variables as JSON input. Everything runs in your browser.

CEL pilot subset
One self-contained CEL expressioncel.bind() gives a local name to a value and returns the result of the final expression.

cel.bind()cel.bind() is an optional official extension. It is not part of the core CEL language and may not be enabled by every host application.

Tip: press Ctrl/⌘ + Enter to run.
Result

Press Run CEL to evaluate the active example.

Pilot scope: literals, explicit conversions, local cel.bind() variables, JSON variables, lists, maps, presence, collection macros, core string checks, time values, arithmetic, comparisons, logic, and the conditional operator.

What you will do

You will run the prepared expression in the playground above, change one input at a time, and explain the result. Start in CEL only, then repeat the same rule in CEL + JSON.

How it works

The expression converts both inputs to timestamps before comparison. This compares instants, including their UTC offsets, rather than relying on the spelling of the strings. <= accepts an event exactly at the deadline as well as an earlier event.

Read the prepared example

The CEL + JSON rule is:

timestamp(receivedAt) <= timestamp(deadline)

Its input is:

{
  "receivedAt": "2026-07-23T09:15:00Z",
  "deadline": "2026-07-23T10:00:00Z"
}

The CEL only tab contains the values and the rule in one expression. The enabled cel.bind() extension keeps each name local to its final argument.

Evaluation step by step

  1. Both RFC 3339 strings are parsed.
  2. 09:15Z occurs before 10:00Z.
  3. The comparison returns true.

Your task

  1. Run the on-time example.
  2. Move receivedAt to 10:01:00Z.
  3. Set it exactly to the deadline and explain the result.

Expected observation: 10:01 is late and returns false; exactly 10:00 returns true because the operator is <=.

Common mistake

String ordering is not a substitute for time parsing when offsets or formatting can differ.

Show the explanation

No. Use <= when equality is considered on time.

Knowledge check

Would < accept an event exactly at the deadline?

Key takeaway

Compare parsed timestamps and choose the boundary operator deliberately.

Sources

  • CEL-DEV — official CEL overview.
  • CEL-LANG — official CEL language definition.
  • CEL-GO-BIND — official documentation for the optional cel.bind() extension used by the self-contained tab.