From owner-freebsd-standards Wed Apr 10 13:28:14 2002 Delivered-To: freebsd-standards@freebsd.org Received: from khavrinen.lcs.mit.edu (khavrinen.lcs.mit.edu [18.24.4.193]) by hub.freebsd.org (Postfix) with ESMTP id EAC7A37B400 for ; Wed, 10 Apr 2002 13:28:08 -0700 (PDT) Received: (from wollman@localhost) by khavrinen.lcs.mit.edu (8.11.4/8.11.6) id g3AKS5h68482; Wed, 10 Apr 2002 16:28:05 -0400 (EDT) (envelope-from wollman) Date: Wed, 10 Apr 2002 16:28:05 -0400 (EDT) From: Garrett Wollman Message-Id: <200204102028.g3AKS5h68482@khavrinen.lcs.mit.edu> To: Sean Chittenden Cc: freebsd-standards@FreeBSD.ORG Subject: Re: mktime() doesn't fix deadzones... In-Reply-To: <20020410125409.B34587@ninja1.internal> References: <200204101233.g3ACXaOF052655@hak.lan.Awfulhak.org> <20020410125409.B34587@ninja1.internal> Sender: owner-freebsd-standards@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG < said: > I like that mktime() returns -1 for invalid times, but I don't think > Apr 7th @2am-8 is an invalid time. Not correct, but not invalid > either. There is no such time as 2001-04-07T0200 when US DST rules are used. This time simply does not exist, and mktime() correctly returns an error. It has no way of knowing that you ``really meant'' 2001-04-07T0300. The way mktime() works is by performing a binary search on the time_t space, after normalization. If it determines that the time you have requested is not a possible return value of localtime(), then it returns an error. (It will also return an error if the time you have requested is not unique, as happens during the autumn transition period if tm_isdst is set to -1.) > Sun Apr 07 02:00:00 PST 2002 =3D 1018173600 ...except that PST is not in effect at that time in your timezone. However, there is a bug here. Perhaps this is fixed in a more recent tzcode; someone should check. The bug has to do with normalization. Consider the following test program fragment: tm.tm_year = 102; tm.tm_mon = 3; tm.tm_mday = 7; tm.tm_hour = 1; tm.tm_min = 61; tm.tm_sec = 0; tm.tm_isdst = -1; t = mktime(&tm); mktime() should not return -1 in this case, because the time specified does in fact exist, after normalization. The normalized time in `tm' should be 2002-04-07T03:02, with tm_isdst positive, which certainly does exist. The current code does not do this. Even worse, the current code returns an error even if tm_isdst is explicitly zero or positive, which should be enough to explicitly identify the time in question. -GAWollman To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-standards" in the body of the message