kolibrios/contrib/kolibri-libc/source/stdlib/mktime.c
Magomed Kostoev (mkostoevr) 1f4d74f500 Relocate kolibri-libc from GitHub
git-svn-id: svn://kolibrios.org@8622 a494cfbc-eb01-0410-851d-a64ba20cac60
2021-03-02 17:58:11 +00:00

24 lines
778 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) + (utc_hrs * 3600) + (timeptr->tm_min * 60) + timeptr->tm_sec;
}