MCPcopy Create free account
hub / github.com/git/git / tm_to_time_t

Function tm_to_time_t

date.c:18–37  ·  view source on GitHub ↗

* This is like mktime, but without normalization of tm_wday and tm_yday. */

Source from the content-addressed store, hash-verified

16 * This is like mktime, but without normalization of tm_wday and tm_yday.
17 */
18time_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
39static const char *month_names[] = {
40 "January", "February", "March", "April", "May", "June",

Callers 5

local_time_tzoffsetFunction · 0.85
set_dateFunction · 0.85
parse_date_basicFunction · 0.85
datestampFunction · 0.85
strbuf_addftimeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected