While running the following C code, I noticed that mktime() apparently does some time zone conversions when called.
void process_time(struct tm * pt) {
printf("pt %02d-%02d-%02d %02d:%02d:%02d\n", pt->tm_year, pt->tm_mon, pt->tm_mday,
pt->tm_hour, pt->tm_min, pt->tm_sec);
ret = mktime(pt);
printf("pt %02d-%02d-%02d %02d:%02d:%02d\n", pt->tm_year, pt->tm_mon, pt->tm_mday,
pt->tm_hour, pt->tm_min, pt->tm_sec);
/* more code here */
}
In some cases (which turned out to be due to some struct tm members not being properly initialized), I noticed that after the call to mktime(), pt->tm_hour was one less than it was before. Local system time is an hour east of UTC, so that corresponds to a local-to-UTC conversion.
According to this source, struct tm should merely have the usual YYYY-MM-DD-hh-mm-ss fields, in addition to weekday, day of the year and a DST flag—no mention of the time zone or UTC offset.
However, when I examine the struct on Ubuntu (/usr/include/time.h), I notice two extra fields for UTC offset and a time zone string.
What is the interface contract for struct tm? Does it mandate these time zone conversions, and if so, how are struct tm members supposed to be interpreted regarding time zones after mktime() has normalized them?