Skip to content

Commit f16d3b1

Browse files
Use UTC Time For GitHub API
When reading the created_at time from the GitHub API, it'll be a naive date string with UTC time, so we use that instead of the system's time. Signed-off-by: Hassan Abouelela <[email protected]>
1 parent 37001bc commit f16d3b1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

pydis_site/apps/api/github_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def authorize(owner: str, repo: str) -> httpx.Client:
148148
def check_run_status(run: WorkflowRun) -> str:
149149
"""Check if the provided run has been completed, otherwise raise an exception."""
150150
created_at = datetime.datetime.strptime(run.created_at, ISO_FORMAT_STRING)
151-
run_time = datetime.datetime.now() - created_at
151+
run_time = datetime.datetime.utcnow() - created_at
152152

153153
if run.status != "completed":
154154
if run_time <= MAX_RUN_TIME:

pydis_site/apps/api/tests/test_github_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CheckRunTests(unittest.TestCase):
4949
"head_sha": "sha",
5050
"status": "completed",
5151
"conclusion": "success",
52-
"created_at": datetime.datetime.now().strftime(github_utils.ISO_FORMAT_STRING),
52+
"created_at": datetime.datetime.utcnow().strftime(github_utils.ISO_FORMAT_STRING),
5353
"artifacts_url": "url",
5454
}
5555

@@ -73,7 +73,7 @@ def test_timeout_error(self):
7373
# Set the creation time to well before the MAX_RUN_TIME
7474
# to guarantee the right conclusion
7575
kwargs["created_at"] = (
76-
datetime.datetime.now() - github_utils.MAX_RUN_TIME - datetime.timedelta(minutes=10)
76+
datetime.datetime.utcnow() - github_utils.MAX_RUN_TIME - datetime.timedelta(minutes=10)
7777
).strftime(github_utils.ISO_FORMAT_STRING)
7878

7979
with self.assertRaises(github_utils.RunTimeoutError):

0 commit comments

Comments
 (0)