mblaze/mytimegm.c

29 lines
556 B
C
Raw Normal View History

#include <time.h>
time_t
mytimegm(struct tm *tm)
{
int mon = tm->tm_mon + 1 - 2; /* put March first, Feb last */
long long year = tm->tm_year + 1900;
2020-03-28 23:19:07 +00:00
if (mon <= 0 || mon >= 12) {
int adj = mon / 12;
mon %= 12;
if (mon <= 0) {
adj--;
mon += 12;
}
year += adj;
}
time_t t = 0;
t += tm->tm_sec;
t += 60 * tm->tm_min;
t += 60*60 * tm->tm_hour;
t += 24*60*60 * (tm->tm_mday - 1);
t += 24*60*60 * (367*mon/12);
t += 24*60*60 * (year/4 - year/100 + year/400);
t += 24*60*60 * (365*year - 719498L);
2017-01-26 19:27:26 +00:00
return t;
}