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

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2022-12-25 15:36:33 -08:00
committed by Tim Abbott
parent b5cad938b8
commit 3e10ceb022

View File

@@ -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))