From c44f300309042d955167525cb4587f92002cc178 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Sat, 26 Aug 2023 20:43:58 +0300 Subject: [PATCH] linkcheck: Use correct function to convert from UTC time to UNIX epoch After subtracting the offset, we get time in UTC. But time.mktime() expects a time struct in local time, not in UTC. The correct function for converting UTC time to UNIX epoch is calendar.timegm(). This fixes hanging tests when the local timezone is to the west of UTC. One could test this using: TZ=America/New_York python3 -m pytest -k test_too_many_requests_retry_after_HTTP_date --- sphinx/builders/linkcheck.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index e1479e01be0..24b9d92cf14 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -2,6 +2,7 @@ from __future__ import annotations +import calendar import contextlib import json import re @@ -491,7 +492,7 @@ def limit_rate(self, response_url: str, retry_after: str) -> float | None: parsed = parsedate_tz(retry_after) assert parsed is not None # the 10th element is the GMT offset in seconds - next_check = time.mktime(parsed[:9]) - (parsed[9] or 0) + next_check = float(calendar.timegm(parsed[:9])) - (parsed[9] or 0) except (AssertionError, TypeError, ValueError): # TypeError: Invalid date format. # ValueError: Invalid date, e.g. Oct 52th.