Skip to content

Commit

Permalink
fix: return a naive UTC object (pypi#14871)
Browse files Browse the repository at this point in the history
  • Loading branch information
miketheman authored Nov 6, 2023
1 parent 179040a commit dc037a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions tests/unit/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
from urllib3.util import parse_url

from warehouse import filters
from warehouse.utils import now


def test_now():
assert isinstance(now(), datetime.datetime)
assert now().tzinfo is None
with pytest.raises(TypeError) as excinfo:
_ = now() < datetime.datetime.now(datetime.UTC)
assert "can't compare offset-naive and offset-aware datetimes" in str(excinfo.value)
assert now() <= datetime.datetime.now()


def test_camo_url():
Expand Down
3 changes: 2 additions & 1 deletion warehouse/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@


def now() -> datetime.datetime:
return datetime.datetime.now(datetime.UTC)
"""Return the current datetime in UTC without a timezone."""
return datetime.datetime.now(datetime.UTC).replace(tzinfo=None)


def dotted_navigator(path):
Expand Down

0 comments on commit dc037a7

Please sign in to comment.