Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions src/humanize/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

from __future__ import annotations

__lazy_modules__ = {"humanize.i18n", "humanize.number"}
__lazy_modules__ = {"datetime", "humanize.i18n", "humanize.number"}

import datetime as dt
from enum import Enum
from functools import total_ordering

Expand All @@ -16,7 +17,6 @@

TYPE_CHECKING = False
if TYPE_CHECKING:
import datetime as dt
from collections.abc import Iterable
from typing import Any

Expand Down Expand Up @@ -47,8 +47,6 @@ def __lt__(self, other: Any) -> Any:


def _now() -> dt.datetime:
import datetime as dt

return dt.datetime.now()


Expand All @@ -74,8 +72,6 @@ def _date_and_delta(

If that's not possible, return `(None, value)`.
"""
import datetime as dt

if not now:
now = _now()
if isinstance(value, dt.datetime):
Expand Down Expand Up @@ -136,8 +132,6 @@ def naturaldelta(
```

"""
import datetime as dt

tmp = Unit[minimum_unit.upper()]
if tmp not in (Unit.SECONDS, Unit.MILLISECONDS, Unit.MICROSECONDS):
msg = f"Minimum unit '{minimum_unit}' not supported"
Expand Down Expand Up @@ -286,8 +280,6 @@ def naturaltime(
Returns:
str: A natural representation of the input in a resolution that makes sense.
"""
import datetime as dt

value = _convert_aware_datetime(value)
when = _convert_aware_datetime(when)

Expand Down Expand Up @@ -316,8 +308,6 @@ def _convert_aware_datetime(
if value is None:
return None

import datetime as dt

if isinstance(value, dt.datetime) and value.tzinfo is not None:
value = dt.datetime.fromtimestamp(value.timestamp())
return value
Expand All @@ -331,8 +321,6 @@ def naturalday(value: dt.date | dt.datetime, format: str = "%b %d") -> str:
formatted according to `format`.

"""
import datetime as dt

try:
# When value is a tz-aware datetime, compute "today" in that timezone
# so the comparison uses the correct local date.
Expand Down Expand Up @@ -363,8 +351,6 @@ def naturalday(value: dt.date | dt.datetime, format: str = "%b %d") -> str:

def naturaldate(value: dt.date | dt.datetime) -> str:
"""Like `naturalday`, but append a year for dates more than ~five months away."""
import datetime as dt

original_value = value
try:
if isinstance(value, dt.datetime) and value.tzinfo is not None:
Expand Down
Loading