Skip to content

Commit

Permalink
linkcheck: Use correct function to convert from UTC time to UNIX epoch
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mitya57 committed Aug 26, 2023
1 parent 5e88b9f commit c44f300
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sphinx/builders/linkcheck.py
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import calendar
import contextlib
import json
import re
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c44f300

Please sign in to comment.