* This is like mktime, but without normalization of tm_wday and tm_yday. */
| 16 | * This is like mktime, but without normalization of tm_wday and tm_yday. |
| 17 | */ |
| 18 | time_t tm_to_time_t(const struct tm *tm) |
| 19 | { |
| 20 | static const int mdays[] = { |
| 21 | 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 |
| 22 | }; |
| 23 | int year = tm->tm_year - 70; |
| 24 | int month = tm->tm_mon; |
| 25 | int day = tm->tm_mday; |
| 26 | |
| 27 | if (year < 0 || year > 129) /* algo only works for 1970-2099 */ |
| 28 | return -1; |
| 29 | if (month < 0 || month > 11) /* array bounds */ |
| 30 | return -1; |
| 31 | if (month < 2 || (year + 2) % 4) |
| 32 | day--; |
| 33 | if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_sec < 0) |
| 34 | return -1; |
| 35 | return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL + |
| 36 | tm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec; |
| 37 | } |
| 38 | |
| 39 | static const char *month_names[] = { |
| 40 | "January", "February", "March", "April", "May", "June", |
no outgoing calls
no test coverage detected