Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #include <time.h>
  2.  
  3. time_t mktime (struct tm * timeptr)
  4. {
  5.     int utcdiff = -3;
  6.     const int mon_days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  7.     unsigned long int tyears, tdays, leaps, utc_hrs;
  8.     int i;
  9.    
  10.     tyears = timeptr->tm_year - 70 ;// tm->tm_year is from 1900.
  11.     leaps = (tyears + 2) / 4; // no of next two lines until year 2100.
  12.     i = (timeptr->tm_year - 100) / 100;
  13.     leaps -= ( (i/4)*3 + i%4 );
  14.     tdays = 0;
  15.     for (i=0; i < timeptr->tm_mon; i++) tdays += mon_days[i];
  16.    
  17.     tdays += timeptr->tm_mday-1; // days of month passed.
  18.     tdays = tdays + (tyears * 365) + leaps;
  19.  
  20.     utc_hrs = timeptr->tm_hour + utcdiff; // for your time zone.
  21.     return (tdays * 86400) + (utc_hrs * 3600) + (timeptr->tm_min * 60) + timeptr->tm_sec;
  22. }
  23.  
  24.