[issue15750] test_localtime_daylight_false_dst_true raises OverflowError: mktime argument out of range
Trent Nelson
report at bugs.python.org
Tue Aug 21 08:48:11 CEST 2012
Trent Nelson added the comment:
All my servers are set to use UTC, which affects how FreeBSD (and other BSDs) treat the isdst param in struct tm in mktime:
#include <stdio.h>
#include <string.h>
#include <time.h>
int main(int argc, char **argv)
{
struct tm tm1, tm2;
time_t t1, t2;
memset((void *)&tm1, 0, sizeof(struct tm));
memset((void *)&tm2, 0, sizeof(struct tm));
// UTC
setenv("TZ", "UTC", 1);
tzset();
tm1.tm_sec = 0;
tm1.tm_min = 1;
tm1.tm_hour = 1;
tm1.tm_mday = 12;
tm1.tm_mon = 3;
tm1.tm_year = 2012;
tm1.tm_wday = -1;
tm1.tm_yday = -1;
tm1.tm_isdst = 1;
t1 = mktime(&tm1);
printf("t1 (UTC): %d\n", t1);
// EST
setenv("TZ", "CET", 1);
tzset();
tm2.tm_sec = 0;
tm2.tm_min = 1;
tm2.tm_hour = 1;
tm2.tm_mday = 12;
tm2.tm_mon = 3;
tm2.tm_year = 2012;
tm2.tm_wday = -1;
tm2.tm_yday = -1;
tm2.tm_isdst = 1;
t2 = mktime(&tm2);
printf("t2 (CET): %d\n", t2);
return 0;
}
% gcc -g test_mktime.c -o test_time && ./test_time
t1 (UTC): -1
t2 (CET): 1162787116
The two tests causing problems are Lib/test/test_email/test_utils.py:
def test_localtime_daylight_false_dst_false(self):
test.support.patch(self, time, 'daylight', False)
t0 = datetime.datetime(2012, 3, 12, 1, 1)
t1 = utils.localtime(t0, isdst=-1)
t2 = utils.localtime(t1)
self.assertEqual(t1, t2)
def test_localtime_daylight_true_dst_true(self):
test.support.patch(self, time, 'daylight', True)
t0 = datetime.datetime(2012, 3, 12, 1, 1)
t1 = utils.localtime(t0, isdst=1)
t2 = utils.localtime(t1)
self.assertEqual(t1, t2)
In order for those tests to work on a *BSD server with a TZ set to UTC, TZ is going to need to be set to something else first, and then tzset() called. Otherwise, mktime() will return -1, which triggers the overflow error.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15750>
_______________________________________
More information about the Python-bugs-list
mailing list