NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
timegm.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stdbool.h>
32#include <time.h>
33
39static bool is_leap_year(int year)
40{
41 return ((year % 400) == 0) || (((year % 4) == 0) && ((year % 100) != 0));
42}
43
49static time_t tm_to_sec(struct tm *tm)
50{
51 time_t val = tm->tm_sec + (tm->tm_min * 60) + (tm->tm_hour * 3600) + (tm->tm_yday * 86400);
52
53 int year = 1900 + tm->tm_year;
54 for (int i = 1970; i < year; i++)
55 {
56 if (is_leap_year(i))
57 val += (366 * 86400);
58 else
59 val += (365 * 86400);
60 }
61
62 return val;
63}
64
70time_t timegm(struct tm *tm)
71{
72 return tm_to_sec(tm);
73}
time_t timegm(struct tm *tm)
Convert struct tm to time_t seconds since epoch.
Definition: timegm.c:70
static time_t tm_to_sec(struct tm *tm)
Convert a time structure to number of seconds since the epoch.
Definition: timegm.c:49
static bool is_leap_year(int year)
Is this a Leap Year?
Definition: timegm.c:39