New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_localtime_daylight_false_dst_true raises OverflowError: mktime argument out of range #59955
Comments
On the FreeBSD 8.2 build slave: ====================================================================== Traceback (most recent call last):
File "/home/buildslave/python/3.x.snakebite-freebsd82-amd64/build/Lib/test/test_email/test_utils.py", line 86, in test_localtime_daylight_false_dst_true
t1 = utils.localtime(t0, isdst=1)
File "/home/buildslave/python/3.x.snakebite-freebsd82-amd64/build/Lib/email/utils.py", line 397, in localtime
seconds = time.mktime(tm)
OverflowError: mktime argument out of range ====================================================================== Traceback (most recent call last):
File "/home/buildslave/python/3.x.snakebite-freebsd82-amd64/build/Lib/test/test_email/test_utils.py", line 79, in test_localtime_daylight_true_dst_true
t1 = utils.localtime(t0, isdst=1)
File "/home/buildslave/python/3.x.snakebite-freebsd82-amd64/build/Lib/email/utils.py", line 397, in localtime
seconds = time.mktime(tm)
OverflowError: mktime argument out of range Placeholder issue, haven't looked into it in detail yet. |
Narrowed it down to the following snippet: >>> time.mktime((2012, 3, 12, 1, 1, 0, 0, 72, -1))
1331514060.0
[70780 refs]
>>> time.mktime((2012, 3, 12, 1, 1, 0, 0, 72, 1))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: mktime argument out of range
[70832 refs] On all my FreeBSD boxes, that latter invocation always raises an OverflowError. |
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;
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);
t2 = mktime(&tm2);
printf("t2 (CET): %d\n", t2);
return 0;
} % gcc -g test_mktime.c -o test_time && ./test_time 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. |
email.utils.localtime() may reuse the new datetime.datetime.timestamp() method, except that this method doesn't support setting isdst (it is set to -1). |
This is 3.3 only, as those tests and the function they test were only introduced in 3.3. |
So you are saying that if the current timezone is UTC, FreeBSD's mktime just arbitrarily returns -1 for any time passed to it with the 'guess the DST flag' value set for is_dst? And for is_dst set to 1 as well? This isn't mentioned on the FreeBSD man page for mktime, as far as I can see. If this is the real problem, we can fix it with the support.run_with_tz decorator, but...compiling and running your program on my linux box, I get -1 in both prints. |
I don't know about FreeBSD, but I recall seeing a comment in mxDT sources that some systems only allow isdst flag of -1 in mktime. Adding Marc-Andre. |
Are these tests still failing, can this issue be closed as "out of date" or what? |
I don't see the issue anymore, I guess that it was fixed. |
I mark this issue as a duplicate of bpo-35317. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: