| |
|
|
| from __future__ import annotations |
|
|
| import datetime as dt |
| import os |
| import sys |
| from pathlib import Path |
|
|
| os.environ["PYTEST_DISABLE_PLUGIN_AUTOLOAD"] = "1" |
| sys.path.insert(0, str(Path(__file__).resolve().parent / "src")) |
|
|
| import humanize |
|
|
|
|
| reference = dt.date(2024, 3, 1) |
| assert humanize.naturalday(dt.date(2024, 2, 29), when=reference) == "yesterday" |
| assert humanize.naturaldate(dt.date(2024, 8, 15), when=reference) == "Aug 15 2024" |
|
|
| minus_ten = dt.timezone(dt.timedelta(hours=-10)) |
| value = dt.datetime(2024, 1, 1, 23, 30, tzinfo=minus_ten) |
| same_instant = dt.datetime(2024, 1, 2, 9, 0, tzinfo=dt.timezone.utc) |
| assert humanize.naturalday(value, when=same_instant) == "today" |
|
|
| try: |
| humanize.naturaldate(dt.date(2024, 1, 1), when="2024-01-01") |
| except TypeError: |
| pass |
| else: |
| raise AssertionError("naturaldate must reject a non-date reference") |
|
|