[Zope3-dev] Daylight savings unittest errors

Barry Pederson bp@barryp.org
Mon, 09 Jun 2003 14:44:30 -0500


Guido van Rossum wrote:

> I have another suggestion, which you may be able to verify by reading
> C code headers (or perhaps even man pages) on your system.
> 
> here's the implementation of mktime():
> 
>   static PyObject *
>   time_mktime(PyObject *self, PyObject *args)
>   {
> 	PyObject *tup;
> 	struct tm buf;
> 	time_t tt;
> 	if (!PyArg_ParseTuple(args, "O:mktime", &tup))
> 		return NULL;
> 	tt = time(&tt);
> 	buf = *localtime(&tt);
> 	if (!gettmarg(tup, &buf))
> 		return NULL;
> 	tt = mktime(&buf);
> 	if (tt == (time_t)(-1)) {
> 		PyErr_SetString(PyExc_OverflowError,
> 				"mktime argument out of range");
> 		return NULL;
> 	}
> 	return PyFloat_FromDouble((double)tt);
>   }
> 
> What's fishy here is that it is making a call to localtime() with the
> current time to initialize "struct tm buf", before calling
> gettmarg(tup, buf).
> 
> Could it be that on FreeBSD there are timezone info fields in the
> struct tm, past the 9 standard fields, which override the tm_isdst
> flag?  That would explain why you always get it interpreted as local
> time, even when tm_isdst is explicitly set to zero.
> 
> If you can confirm this, maybe time_mktime() can be fixed to do
> something different if such extra tzinfo fields exist?

 From FreeBSD 4.8 /usr/include/time.h
-----------
struct tm {
         int     tm_sec;         /* seconds after the minute [0-60] */
         int     tm_min;         /* minutes after the hour [0-59] */
         int     tm_hour;        /* hours since midnight [0-23] */
         int     tm_mday;        /* day of the month [1-31] */
         int     tm_mon;         /* months since January [0-11] */
         int     tm_year;        /* years since 1900 */
         int     tm_wday;        /* days since Sunday [0-6] */
         int     tm_yday;        /* days since January 1 [0-365] */
         int     tm_isdst;       /* Daylight Savings Time flag */
         long    tm_gmtoff;      /* offset from CUT in seconds */
         char    *tm_zone;       /* timezone abbreviation */
};
-----------

I took a look at the library source

http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/stdtime/localtime.c?rev=1.25.2.2&content-type=text/x-cvsweb-markup

But it's a bit much to try and digest on my day off :)  Not quite sure what 
  to make of it.

	Barry