lunch-poll-legacy

Lunch Poll Legacy -- poll colleagues where to have lunch
Log | Files | Refs | README | LICENSE

date-utils.c (501B)


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