Skip to content

Commit

Permalink
Fix datetime.utcnow deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Mar 15, 2024
1 parent eb8545c commit 261fc8d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ async def permission_allowed(
used_default = True
self._permission_checks.append(
{
"when": datetime.datetime.utcnow().isoformat(),
"when": datetime.datetime.now(datetime.timezone.utc).isoformat(),
"actor": actor,
"action": action,
"resource": resource,
Expand Down
7 changes: 5 additions & 2 deletions datasette/default_magic_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ def now(key, request):
if key == "epoch":
return int(time.time())
elif key == "date_utc":
return datetime.datetime.utcnow().date().isoformat()
return datetime.datetime.now(datetime.timezone.utc).date().isoformat()
elif key == "datetime_utc":
return datetime.datetime.utcnow().strftime(r"%Y-%m-%dT%H:%M:%S") + "Z"
return (
datetime.datetime.now(datetime.timezone.utc).strftime(r"%Y-%m-%dT%H:%M:%S")
+ "Z"
)
else:
raise KeyError

Expand Down

0 comments on commit 261fc8d

Please sign in to comment.