← All Exercises

Classify an API Version Lifecycle Stage

basicjavascript~20min

Background

API portability depends on consumers knowing when a version stops being supported. A stage function makes release notes and deprecation headers agree.

Problem

From a version and a deprecation record (announcement and sunset timestamps), return whether the version is current, deprecated, or sunset for a given review time.

Input

JSON object: { version, now, deprecation?: { announcedAt, sunsetAt } }

Output

JSON object: { version, stage }

Sample tests

Sample 1

Input: {"version":"2024-06","now":"2024-03-01T00:00:00Z","deprecation":{"announcedAt":"2024-06-01T00:00:00Z","sunsetAt":"2024-12-01T00:00:00Z"}}
Expected: {"version":"2024-06","stage":"current"}

Sample 2

Input: {"version":"2024-06","now":"2024-09-01T00:00:00Z","deprecation":{"announcedAt":"2024-06-01T00:00:00Z","sunsetAt":"2024-12-01T00:00:00Z"}}
Expected: {"version":"2024-06","stage":"deprecated"}

Your solution

Learning objective

Derive lifecycle stage from dates instead of remembering release notes.