kolibrios-gitea/programs/develop/ktcc/trunk/libc.obj/source/time/mktime.c
turbocat cde4fa851d libc.obj:
- Formatted by clang-format (WebKit-style).
- Removed unnecessary errno linux. 
- Added KOS error codes. 
- String functions have been replaced with more optimal ones for x86. 
- Changed wrappers for 70 sysfunction.

git-svn-id: svn://kolibrios.org@9765 a494cfbc-eb01-0410-851d-a64ba20cac60
2022-04-15 09:00:55 +00:00

23 lines
799 B
C

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