Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

ruff: Fix DTZ007 `datetime.datetime.strptime()` without %z.

Anders Kaseorg3e10ceb02250
diff --git a/zerver/lib/validator.py b/zerver/lib/validator.py
index b83ff74cfa3..af35fd5e274 100644
--- a/zerver/lib/validator.py
+++ b/zerver/lib/validator.py
@@ -30,7 +30,7 @@ for any particular type of object.
import re
import sys
from dataclasses import dataclass
-from datetime import datetime
+from datetime import datetime, timezone
from decimal import Decimal
from typing import (
Any,
@@ -147,7 +147,10 @@ def check_date(var_name: str, val: object) -> str:
if not isinstance(val, str):
raise ValidationError(_("{var_name} is not a string").format(var_name=var_name))
try:
- if datetime.strptime(val, "%Y-%m-%d").strftime("%Y-%m-%d") != val:
+ if (
+ datetime.strptime(val, "%Y-%m-%d").replace(tzinfo=timezone.utc).strftime("%Y-%m-%d")
+ != val
+ ):
raise ValidationError(_("{var_name} is not a date").format(var_name=var_name))
except ValueError:
raise ValidationError(_("{var_name} is not a date").format(var_name=var_name))