Message-Id: <199709031239.IAA00721@delorie.com> From: Oberhumer Markus Subject: 970831: mktime() To: dj AT delorie DOT com (DJ Delorie), djgpp-workers AT delorie DOT com (djgpp-workers) Date: Wed, 3 Sep 1997 14:33:21 +0200 (METDST) Return-Read-To: markus DOT oberhumer AT jk DOT uni-linz DOT ac DOT at Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk Subject: 970831: mktime() > mktime() "fix" for dates within a daylight savings time change (i.e. > two possible time_t results): I think that this *is* an error, and > mktime should return -1. However, the original problem still exists: > converting dos m/d/y to a unix time_t. Would it be better to just > call mktime twice at the right spot: if it fails the first time, add > an hour, call mktime, then subtract an hour from the result. Sounds reasonable. What do you think about the new function below ? Functions that know that they have valid DOS-dates should call this instead of mktime() - in libc these are stat() [xstat.c] and gettimeofday() [gettimeo.c]. Markus time_t __djgpp_safe_mktime(struct tm *tptr) { int diff = 0; struct tm saved_tm = *tptr; time_t t; /* search for a valid timestamp within the next 8 hours */ while (diff <= 8 * 3600) { t = mktime(tptr); if (t != ((time_t)-1) && t >= (time_t) diff) return t - diff; /* restore time */ *tptr = saved_tm; /* try 15 minutes later */ diff += 15 * 60; tptr->tm_sec += diff; } /* give up */ return ((time_t)-1); }