Loading...
Searching...
No Matches
nightsched.h File Reference

Whether a night-time window is open right now, from plain clock readings. More...

#include <stdbool.h>

Go to the source code of this file.

Enumerations

enum  NightSchedMode { NIGHT_SCHED_OFF = 0 , NIGHT_SCHED_SOLAR , NIGHT_SCHED_FIXED , NIGHT_SCHED_COUNT }
 What the schedule is following. The caller's own enum should line up with these. More...

Functions

bool clock_window_contains (int start, int end, int now)
 Whether now falls inside a window that may run past midnight.
bool night_schedule_active (int mode, int now, int rise, int set, int fixed_start, int fixed_end, bool have_night)
 Whether the night window is open, whichever way the schedule is set.

Detailed Description

Whether a night-time window is open right now, from plain clock readings.

A face that swaps its look after dark has to answer one question every minute: is it night? This answers it by asking whether now falls inside a window rather than by watching for the moment it crossed one. That matters more than it looks. An edge-detecting version misses its cue whenever the clock jumps for daylight saving, whenever the app was asleep at the crossing, or whenever a tick is simply dropped, and once it has missed it stays wrong until the next crossing comes round. Containment cannot get stuck: it is right again on the very next minute.

Every reading comes in as minutes past midnight, and -1 means there is no reading. The caller gathers them. Nothing here touches a watch, which is what keeps it host-testable.