Skip to content
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

linkcheck: Use correct function to convert from UTC time to UNIX epoch #11649

Merged
merged 6 commits into from Aug 28, 2023

Conversation

mitya57
Copy link
Contributor

@mitya57 mitya57 commented Aug 26, 2023

Subject: linkcheck: Use correct function to convert from UTC time to UNIX epoch

Feature or Bugfix

  • Bugfix

Purpose

After subtracting the offset, we get time in UTC. But time.mktime() expects a time struct in local time, not in UTC. Quoting the Python documentation:

Use the following functions to convert between time representations:

From To Use
seconds since the epoch struct_time in UTC gmtime()
seconds since the epoch struct_time in local time localtime()
struct_time in UTC seconds since the epoch calendar.timegm()
struct_time in local time seconds since the epoch mktime()

So in our case, the correct function to use 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

After applying this change, the test passes with timezones from both western and eastern hemispheres.

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
@AA-Turner
Copy link
Member

Should we add a test for this? Please could you also add an entry to CHANGES, this will go into 7.2.3.

A

@mitya57
Copy link
Contributor Author

mitya57 commented Aug 27, 2023

Done.

CHANGES Outdated Show resolved Hide resolved
@AA-Turner AA-Turner enabled auto-merge (squash) August 28, 2023 03:34
@AA-Turner AA-Turner merged commit 2f025a4 into sphinx-doc:master Aug 28, 2023
27 checks passed
@mitya57 mitya57 deleted the timegm branch August 28, 2023 06:59
AA-Turner added a commit that referenced this pull request Aug 28, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants