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

The progress sums: seconds gone over seconds in the period, as a whole percent. More...

#include "clock/progress.h"
#include "clock/date.h"

Macros

#define SECS_PER_HOUR   3600
 Seconds in an hour.
#define SECS_PER_DAY   86400
 Seconds in a day on the wall clock, which is always 24 hours.

Functions

static int pct_of_seconds (int elapsed, int total)
 Seconds gone over seconds in the period, as a whole percent rounded down.
static int seconds_into_day (int hour, int min, int sec)
 How many seconds of the day have gone by on the wall clock.
static int days_in_year (int year)
 How many days a year has, 365 or 366.
int progress_week_day (int wday, int week_start)
 How many days the week has run, counting the first day as day 1.
int progress_hour_pct (int min, int sec)
 How far through the current hour it is.
int progress_day_pct (int hour, int min, int sec)
 How far through the current day it is.
int progress_week_pct (int wday, int week_start, int hour, int min, int sec)
 How far through the current week it is, counting from the day the week starts on.
int progress_year_pct (int year, int yday, int hour, int min, int sec)
 How far through the current year it is, with February getting its leap day.

Detailed Description

The progress sums: seconds gone over seconds in the period, as a whole percent.

Function Documentation

◆ days_in_year()

int days_in_year ( int year)
static

How many days a year has, 365 or 366.

January 1st has every day of the year still ahead of it bar itself, so that count plus one is the year's length, with the leap rule kept in date.c alone.

Parameters
yearThe full year (2026, not 126).
Returns
The day count, 365 or 366.

◆ pct_of_seconds()

int pct_of_seconds ( int elapsed,
int total )
static

Seconds gone over seconds in the period, as a whole percent rounded down.

Every period is a whole number of hours, so a hundredth of one is a whole number of seconds, 36 an hour. Dividing by that hundredth gives the same answer as times 100 over the total, with no product that could run past a 32 bit int on a year of seconds. It also keeps 64 bit division, about 750 bytes of library code, off the watch.

Parameters
elapsedSeconds gone so far.
totalSeconds in the whole period, a whole number of hours.
Returns
Whole percent from 0 to 99, or 0 when either count is not positive.

◆ seconds_into_day()

int seconds_into_day ( int hour,
int min,
int sec )
static

How many seconds of the day have gone by on the wall clock.

Parameters
hourThe hour, 0 to 23.
minThe minute, 0 to 59.
secThe second, 0 to 59.
Returns
Seconds since midnight.