PC05-L02 · independent challenge

Deadline with grace period

Add configurable grace to a deadline and compare the received time.

Practical CEL4 test casesDocumented
What will I practise?

You can combine timestamp, duration, and the <= boundary safely.

How is it checked?

Your one expression must produce the expected result for all four JSON inputs.

When am I done?

When all tests pass and you can explain every condition in your expression.

Word problem

A received item is on time when it arrives no later than the deadline plus a configured grace duration.

Exact requirements

  1. Parse received time and deadline as timestamps.
  2. Parse grace as duration.
  3. Add grace to the deadline.
  4. Include the exact last accepted instant.

Required result

Write one CEL expression. It must return the expected value and type for all four prepared JSON inputs. Do not change the inputs to make an incomplete expression pass.

Recommended procedure

  1. Translate each numbered requirement into one small boolean condition.
  2. Run the starter expression and inspect which cases fail.
  3. Add one condition at a time and run the complete suite again.
  4. Mark the challenge complete only when you can explain every operator and every boundary.

Solve the challenge · browser test suite

Write one expression that passes every case

Edit the CEL expression, then run it against all prepared JSON inputs. A solution is complete only when every case passes.

4 test cases

Hint: First create the last accepted instant by adding the duration.

Tip: press Ctrl/⌘ + Enter to run all tests.
Before deadlineNot run yet
Expected: true · bool
Show JSON input
{
  "receivedAt": "2026-07-23T09:50:00Z",
  "deadline": "2026-07-23T10:00:00Z",
  "grace": "15m"
}
Inside grace periodNot run yet
Expected: true · bool
Show JSON input
{
  "receivedAt": "2026-07-23T10:10:00Z",
  "deadline": "2026-07-23T10:00:00Z",
  "grace": "15m"
}
Exact grace boundaryNot run yet
Expected: true · bool
Show JSON input
{
  "receivedAt": "2026-07-23T10:15:00Z",
  "deadline": "2026-07-23T10:00:00Z",
  "grace": "15m"
}
After grace periodNot run yet
Expected: false · bool
Show JSON input
{
  "receivedAt": "2026-07-23T10:15:01Z",
  "deadline": "2026-07-23T10:00:00Z",
  "grace": "15m"
}
Test result

Not run yet

The same expression runs against every case. Test data is fixed so that boundary and failure scenarios cannot be skipped.

Explained solution

Show the complete expression
timestamp(receivedAt) <= timestamp(deadline) + duration(grace)

Why the solution works

  1. timestamp(deadline) + duration(grace) calculates the extended deadline.
  2. The result of that addition is a timestamp.
  3. timestamp(receivedAt) creates a comparable instant.
  4. <= includes an arrival exactly at the grace boundary.

What the test cases prove

  • Before deadline: expected true (bool).
  • Inside grace period: expected true (bool).
  • Exact grace boundary: expected true (bool).
  • After grace period: expected false (bool).

The cases are intentionally different. A solution that passes only the first case has not yet implemented the complete rule.

Common mistake

Do not optimise the expression for the first successful input. A requirement is implemented only when its positive case, negative case, and boundary case all produce the stated result.

Knowledge check

Can you point to the exact part of the solution that makes each false test case fail? If two different failures depend on the same condition, explain why.

Key takeaway

You can combine timestamp, duration, and the <= boundary safely.

Sources

  • CEL-DEV — official CEL overview.
  • CEL-LANG — official CEL language definition for operators, types, macros, presence, strings, and time values used in this challenge.