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

Pure calendar math, host-testable off-device. More...

#include "clock/date.h"

Functions

static int is_leap (int year)
 Whether a year is a leap year, by the usual rule.
static int dec31_wday (int year)
 The weekday December 31st lands on for a year.
int date_iso_weeks_in_year (int year)
 How many ISO 8601 weeks a year holds, either 52 or 53.
static int raw_week (int yday, int wday)
 The week number worked out from the date alone, before the year boundary is taken into account.
int date_iso_week (int year, int yday, int wday)
 The ISO 8601 week number, which always counts weeks from Monday.
int date_iso_week_year (int year, int yday, int wday)
 The ISO 8601 year the week number belongs to, which is not always the calendar year.
int date_day_of_year (int yday)
 Which day of the year it is, counting January 1st as day 1.
int date_days_left_in_year (int year, int yday)
 How many days are left before the year ends, so December 31st reads 0.
int date_days_in_month (int year, int mon0)
 How many days a month has, with February getting its leap day.
int date_first_wday (int wday, int mday)
 The weekday the 1st of the month lands on, walked back from today's weekday.

Detailed Description

Pure calendar math, host-testable off-device.

Function Documentation

◆ dec31_wday()

int dec31_wday ( int year)
static

The weekday December 31st lands on for a year.

Parameters
yearThe full year (2026, not 126).
Returns
The weekday, 0 Sunday to 6 Saturday.

◆ is_leap()

int is_leap ( int year)
static

Whether a year is a leap year, by the usual rule.

Every fourth year is one, except a century year, unless it also divides evenly by 400.

Parameters
yearThe full year (2026, not 126).
Returns
True when the year has a leap day, false when it does not.

◆ raw_week()

int raw_week ( int yday,
int wday )
static

The week number worked out from the date alone, before the year boundary is taken into account.

A number below 1 means the day belongs to last year's final week. A number above the year's own total means it already belongs to next year's week 1. The ISO weekday used here runs Monday as 1 through Sunday as 7.

Parameters
ydayThe day of the year counting January 1st as 0 (like tm_yday).
wdayThe weekday, 0 Sunday to 6 Saturday.
Returns
The raw week number, which may fall outside 1 to the year's own week count.