CH06-L03 · applied

Time components and time zones

Read the year and month from a timestamp in UTC.

General CELRuns hereDocumented
What will I learn?

You know that getMonth() uses 0 through 11 and that a time zone must be chosen deliberately.

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

Timestamp accessor methods expose calendar components. getFullYear() returns the year, while getMonth() uses zero-based months: January is 0 and July is 6. Without a time-zone argument, these accessors use UTC in CEL.

Read the prepared example

The CEL + JSON rule is:

timestamp(eventAt).getFullYear() == 2026 && timestamp(eventAt).getMonth() == 6

Its input is:

{
  "eventAt": "2026-07-23T09:15: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. The input is parsed as a UTC timestamp.
  2. getFullYear() returns 2026.
  3. getMonth() returns 6, so both comparisons are true.

Your task

  1. Run the example.
  2. Change the expected month from 6 to 7 and observe false.
  3. Change the date to 2026-08-01T00:00:00Z and run again.

Expected observation: July compares with 6; August compares with 7.

Common mistake

Human month numbers usually start at 1, but getMonth() starts at 0. Document that boundary wherever people enter month numbers.

Show the explanation

0.

Knowledge check

What does getMonth() return for January?

Key takeaway

Calendar accessors have precise conventions: UTC by default and zero-based month numbers.

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.