Diese Funktion berechnet zu einem gegebenen Datum den Wochentag mit Hilfe der Gaußschen Wochentagsformel.
Parameter:#include <math.h> typedef struct{ uint16_t year; uint8_t month; uint8_t day; } stc_date; uint8_t MyGetWeekday(stc_date date) { // Calculate weekday of a given date by using gauss algorithm uint8_t h = 0; // Weekday uint16_t year = (date).year; // Year (4 digits) uint8_t m = (date).month; // Month uint8_t q = (date).day; // Day if (m < 3) // January = 13th, February = 14th of previous year { m += 12; year--; } uint8_t J = (uint8_t) ((uint16_t) year / (uint16_t) 100); // Century (first 2 digits) uint8_t K = (uint8_t) ((uint16_t) year - ((uint16_t) J * (uint16_t) 100)); // year in century (last 2 digits) h = ((q + floor(((m+1)*26)/10) + K + floor(K/4) + (J/4) - (2*J))); // applying Gauss formula h %= 7; return h; }