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

The window sums: build one, place a moment on it, and clip a span to it. More...

#include "clock/timeband.h"
#include "math/scale.h"

Macros

#define SECONDS_PER_MINUTE   60
 Seconds in a minute, so the epoch maths reads as what it is.

Functions

static int wrap_day (int minutes)
 Bring any minute count into 0..1439, counting backwards from midnight for a negative one.
static int floor_minutes (int seconds)
 Whole minutes in a second count, rounding down so a part minute before the window still counts as the minute it started in.
static int ceil_minutes (int seconds)
 Whole minutes in a second count, rounding up so a span ending part way through a minute still covers it.
TimeBand timeband_full_day (void)
 A window running midnight to midnight.
TimeBand timeband_rolling (int now_min, int span_min, int lead_min)
 A window that puts a given moment a fixed way into it.
TimeBand timeband_from_hour (int base_hour, int span_min)
 A window starting at the top of a given hour.
int timeband_offset (TimeBand band, int minute_of_day)
 How far into the window a minute of the day falls.
int timeband_pos (TimeBand band, int length, int minute_of_day)
 Where a minute of the day lands along an axis of a given length.
int timeband_pos_offset (TimeBand band, int length, int offset_min)
 The same mapping for a value already measured from the window's start.
bool timeband_clip (TimeBand band, time_t window_epoch, time_t start, time_t end, TimeBandSpan *out)
 Clip an absolute span onto the window.
int timeband_clip_daily (TimeBand band, int from_min, int to_min, TimeBandSpan *out, int max_out)
 Clip a daily span, one that repeats every day like the daylight, onto the window.
time_t timeband_window_epoch (TimeBand band, time_t now, int now_min)
 The epoch the window's first minute sits at.

Detailed Description

The window sums: build one, place a moment on it, and clip a span to it.

Function Documentation

◆ ceil_minutes()

int ceil_minutes ( int seconds)
static

Whole minutes in a second count, rounding up so a span ending part way through a minute still covers it.

Parameters
secondsThe count, which may be negative.
Returns
The count in minutes.

◆ floor_minutes()

int floor_minutes ( int seconds)
static

Whole minutes in a second count, rounding down so a part minute before the window still counts as the minute it started in.

Parameters
secondsThe count, which may be negative.
Returns
The count in minutes.

◆ wrap_day()

int wrap_day ( int minutes)
static

Bring any minute count into 0..1439, counting backwards from midnight for a negative one.

Parameters
minutesThe count to wrap.
Returns
The same moment of the day, 0 to 1439.