2016-08-08 14:28:25 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
2020-03-28 20:29:34 +00:00
|
|
|
time_t
|
|
|
|
mytimegm(struct tm *tm)
|
2016-08-08 14:28:25 +00:00
|
|
|
{
|
2020-03-28 20:29:34 +00:00
|
|
|
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;
|
|
|
|
}
|
2020-03-28 20:29:34 +00:00
|
|
|
|
|
|
|
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;
|
2016-08-08 14:28:25 +00:00
|
|
|
}
|