2021-04-27 18:33:31 +02:00
|
|
|
#include <time.h>
|
|
|
|
|
2022-04-15 11:00:55 +02:00
|
|
|
time_t mktime(struct tm* timeptr)
|
2021-04-27 18:33:31 +02:00
|
|
|
{
|
2022-04-15 11:00:55 +02:00
|
|
|
// int utcdiff = -3;
|
|
|
|
const int mon_days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
2021-04-27 18:33:31 +02:00
|
|
|
unsigned long int tyears, tdays, leaps, utc_hrs;
|
|
|
|
int i;
|
2022-04-15 11:00:55 +02:00
|
|
|
|
|
|
|
tyears = timeptr->tm_year - 70; // tm->tm_year is from 1900.
|
2021-04-27 18:33:31 +02:00
|
|
|
leaps = (tyears + 2) / 4; // no of next two lines until year 2100.
|
|
|
|
i = (timeptr->tm_year - 100) / 100;
|
2022-04-15 11:00:55 +02:00
|
|
|
leaps -= ((i / 4) * 3 + i % 4);
|
2021-04-27 18:33:31 +02:00
|
|
|
tdays = 0;
|
2022-04-15 11:00:55 +02:00
|
|
|
for (i = 0; i < timeptr->tm_mon; i++)
|
|
|
|
tdays += mon_days[i];
|
|
|
|
|
|
|
|
tdays += timeptr->tm_mday - 1; // days of month passed.
|
2021-04-27 18:33:31 +02:00
|
|
|
tdays = tdays + (tyears * 365) + leaps;
|
|
|
|
|
2022-04-15 11:00:55 +02:00
|
|
|
// utc_hrs = timeptr->tm_hour + utcdiff; // for your time zone.
|
2021-11-07 20:29:12 +01:00
|
|
|
return (tdays * 86400) + (timeptr->tm_hour * 3600) + (timeptr->tm_min * 60) + timeptr->tm_sec;
|
2022-04-15 11:00:55 +02:00
|
|
|
}
|