Files
radiantwave/src/schedule/schedule_engine.h
T
NeilClack 509c925480 Kiosk: schedule client (conditional GET + atomic cache) and engine
Adds api_client support for GET /licenses/{key}/schedule with If-None-Match
and target-payload parsing (version/type/daily/weekly + legacy blocks), an
atomic on-disk schedule cache, a pure schedule engine (half-open blocks,
midnight self-wrap for daily, Sunday->Monday spillover for weekly, invalid
blocks skipped with a warning), and a background ScheduleManager that loads
the cache offline and pulls on boot and every 5 minutes. Adds engine/cache
tests against the shared docs/fixtures, including 304, corrupt cache, and
offline cases.
2026-09-29 10:34:40 -05:00

37 lines
1.4 KiB
C++

#pragma once
#include "network/api_client.h"
#include <functional>
#include <string>
namespace radiantwave::schedule {
// Weekday keys matching the wire format.
enum class Weekday { Mon = 0, Tue, Wed, Thu, Fri, Sat, Sun };
// The result of evaluating a schedule at a wall-clock instant.
struct Decision {
bool hasBlock = false;
api::TargetBlock block; // valid only when hasBlock
};
// The active Block for `payload` at (minutes, weekday), or none. Implements the
// contract: half-open [start, end), midnight-crossing Blocks belong to their
// start day (weekly Sunday spills into Monday), and a weekly mode must also
// consider the previous day's crossing Block. Invalid Blocks (empty
// proclamation list / bad range) are skipped and treated as gaps.
//
// Wall-clock minutes are passed in, so DST transitions behave naturally (the
// caller supplies the local wall-clock time in the Kiosk's timezone).
Decision evaluate(const api::SchedulePayload& payload, int minutes, Weekday weekday,
std::function<void(const std::string&)> warn = nullptr);
// True when `minutes` falls in the half-open [start, end) block, accounting for
// a midnight-crossing range.
bool minuteInBlock(int minutes, int startMinutes, int endMinutes);
// Weekday from a 0=Monday..6=Sunday index (clamped).
Weekday weekdayFromIndex(int index);
} // namespace radiantwave::schedule