RECENTLY CHECKED
All projects →
Turn data into a physical briefing · STAGE 2 OF 4

Make old readings visibly different

Carry your temperature formatter into a panel that knows when a reading is missing, invalid or too old to use as current.

You needA browser. Use the supplied sample timestamp and adjustable clock; no sensor or API account required.

Reference checked 9 September 2026. Authored exercise; no physical build result is claimed.

Understand the change

  1. Keep the valid value rule

    Carry forward the stage-one rule: zero is valid; a numeric string is not. Add measuredAt without weakening that validation.

  2. Make time inspectable

    Use the sample observation at 08:00 UTC. Move the example clock through 08:04, 08:05 and 08:06. The five-minute limit is our exercise policy, not a universal sensor rule.

  3. Break the timestamp

    Remove measuredAt, make it invalid or set it after the example clock. Each case becomes unavailable. Do not substitute the browser time for an unknown observation time.

  4. Save the state contract

    Keep the function and examples. The next stage uses the same three states when a request fails or supplies an old value.

THE BRIEF

A focused request to try

Use this with a suitable AI assistant. Its response will vary; compare it with the checks below.

Extend the temperature formatter with a measuredAt ISO timestamp. Treat sample readings older than five minutes as stale; exactly five minutes is still current. Reject missing or invalid timestamps, future readings, wrong units and nonnumeric temperatures. Accept now as an argument so tests are repeatable. Keep the old value visible when stale but label it.
THE REFERENCE

Worked reference example

Read the example, predict one change, then check the result.

function readingStatus(data, now, maxAgeMs = 300000) {
  const measured = typeof data?.measuredAt === "string"
    ? Date.parse(data.measuredAt) : NaN;
  if (typeof data?.temperature !== "number" ||
      !Number.isFinite(data.temperature) || data.unit !== "C" ||
      !Number.isFinite(measured) || !Number.isFinite(now) ||
      !Number.isFinite(maxAgeMs) || maxAgeMs < 0 || measured > now) {
    return {state: "unavailable", text: "Unavailable"};
  }
  const stale = now - measured > maxAgeMs;
  return {state: stale ? "stale" : "current",
    text: `${data.temperature} °C${stale ? " · Stale" : ""}`};
}
const sample = {temperature:18, unit:"C", measuredAt:"2026-09-09T08:00:00Z"};
console.assert(readingStatus(sample, Date.parse("2026-09-09T08:05:00Z")).state === "current");
console.assert(readingStatus(sample, Date.parse("2026-09-09T08:05:01Z")).state === "stale");
TRY THE WORKING EXAMPLE

Move the clock, inspect the reading

These are labelled sample responses. The exercise makes no external requests.

DISPLAY OUTPUT18 °C

Change the numeric value to a string, remove its timestamp or set a future timestamp. Then check the result.

Check your result

  • 08:05:00 is current; 08:05:01 is stale.
  • Zero remains visible as 0 °C.
  • Future and invalid timestamps are unavailable, not current.

Where this can go wrong

A timestamp states when the data was measured or issued, not when you downloaded it. Real feeds may have different update intervals and time-zone conventions.

Go to the source

MDN Date.parse reference. Confirm current tool instructions before using them.

Tell us where this exercise was unclear