関数 | |
static int | is_leap (unsigned y) |
time_t | rep_timegm (struct tm *tm) |
static int is_leap | ( | unsigned | y | ) | [static] |
time_t rep_timegm | ( | struct tm * | tm | ) |
参照先 is_leap().
00048 { 00049 static const unsigned ndays[2][12] ={ 00050 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, 00051 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}}; 00052 time_t res = 0; 00053 unsigned i; 00054 00055 if (tm->tm_mon > 12 || 00056 tm->tm_mon < 0 || 00057 tm->tm_mday > 31 || 00058 tm->tm_min > 60 || 00059 tm->tm_sec > 60 || 00060 tm->tm_hour > 24) { 00061 /* invalid tm structure */ 00062 return 0; 00063 } 00064 00065 for (i = 70; i < tm->tm_year; ++i) 00066 res += is_leap(i) ? 366 : 365; 00067 00068 for (i = 0; i < tm->tm_mon; ++i) 00069 res += ndays[is_leap(tm->tm_year)][i]; 00070 res += tm->tm_mday - 1; 00071 res *= 24; 00072 res += tm->tm_hour; 00073 res *= 60; 00074 res += tm->tm_min; 00075 res *= 60; 00076 res += tm->tm_sec; 00077 return res; 00078 }