date-utils.c (455B)
1 /** 2 * Lunch Poll Legacy 3 * Copyright 2024, 2025 Matthias Balk 4 */ 5 6 #include <sys/types.h> 7 #include <time.h> 8 #include <string.h> 9 10 #include "date-utils.h" 11 12 u_int8_t get_day_of_week(const char* date) 13 { 14 struct tm tm; 15 memset(&tm, 0, sizeof(tm)); 16 if (strptime(date, "%Y-%m-%d", &tm) == NULL) { 17 return 0; 18 } 19 20 /* tm_wday: Day of the week [0, 6] (Sunday = 0) */ 21 if (tm.tm_wday == 0) { 22 return DOW_SUN; 23 } 24 return 0x1 << (tm.tm_wday - 1); 25 }