Loading...
Searching...
No Matches
solar.c File Reference

How the day's light is going, worked out from three plain clock readings. More...

#include "clock/solar.h"

Macros

#define MINUTES_PER_DAY   1440
 A day's worth of minutes, for wrapping the night span across midnight.

Functions

static bool have_all (int rise, int set, int now)
 Whether all three readings are real minutes of the day, so the maths below is not run on a missing time. Sunrise and sunset landing on the same minute also count as missing, since that could be a sun that never sets or one that never rises and there is no telling which.
static int forward (int from, int to)
 Minutes going forward round the clock from one reading to another.
int solar_day_progress (int rise, int set, int now)
 How far through the daylight it is, from 0 at sunrise to 100 at sunset.
int solar_night_progress (int rise, int set, int now)
 How far through the night it is, from 0 at sunset to 100 at the next sunrise.
int solar_next_event (int rise, int set, int now, bool *is_sunrise)
 Minutes until the next sun event, and which one it is.

Detailed Description

How the day's light is going, worked out from three plain clock readings.

Function Documentation

◆ forward()

int forward ( int from,
int to )
static

Minutes going forward round the clock from one reading to another.

Sunset falls after midnight in a high latitude summer, so the daylight can run from 03:00 round to 00:30. Measuring everything forward from sunrise this way covers that and an ordinary day with the same maths.

Parameters
fromThe earlier reading, minutes past midnight.
toThe later reading, minutes past midnight.
Returns
0 to 1439.

◆ have_all()

bool have_all ( int rise,
int set,
int now )
static

Whether all three readings are real minutes of the day, so the maths below is not run on a missing time. Sunrise and sunset landing on the same minute also count as missing, since that could be a sun that never sets or one that never rises and there is no telling which.

Parameters
riseSunrise, minutes past midnight, or -1 for no data.
setSunset, minutes past midnight, or -1 for no data.
nowThe clock, minutes past midnight, or -1 for no data.
Returns
True when all three are real readings and the sun both rises and sets.