Subversion Repositories Kolibri OS

Rev

Rev 9260 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <sys/ksys.h>
  2. #include <time.h>
  3.  
  4. time_t time(time_t* timer)
  5. {
  6.     static struct tm __buffertime;
  7.     int kos_date, kos_time;
  8.     kos_date = _ksys_get_date().val;
  9.     kos_time = _ksys_get_time().val;
  10.  
  11.     int bcd_day = (kos_date >> 16);
  12.     int bcd_mon = ((kos_date & 0xFF00) >> 8);
  13.     int bcd_year = (kos_date & 0xFF);
  14.     __buffertime.tm_mday = ((bcd_day & 0xF0) >> 4) * 10 + (bcd_day & 0x0F);
  15.     __buffertime.tm_mon = ((bcd_mon & 0xF0) >> 4) * 10 + (bcd_mon & 0x0F) - 1;
  16.     __buffertime.tm_year = ((bcd_year & 0xF0) >> 4) * 10 + (bcd_year & 0x0F) + 100;
  17.  
  18.     __buffertime.tm_wday = __buffertime.tm_yday = __buffertime.tm_isdst = -1; /* temporary */
  19.  
  20.     int bcd_sec = (kos_time >> 16);
  21.     int bcd_min = ((kos_time & 0xFF00) >> 8);
  22.     int bcd_hour = (kos_time & 0xFF);
  23.  
  24.     __buffertime.tm_sec = ((bcd_sec & 0xF0) >> 4) * 10 + (bcd_sec & 0x0F);
  25.     __buffertime.tm_min = ((bcd_min & 0xF0) >> 4) * 10 + (bcd_min & 0x0F);
  26.     __buffertime.tm_hour = ((bcd_hour & 0xF0) >> 4) * 10 + (bcd_hour & 0x0F);
  27.  
  28.     time_t ret = mktime(&__buffertime);
  29.     if (timer) {
  30.         *timer = ret;
  31.     }
  32.     return ret;
  33. }
  34.