File size: 885 Bytes
598316f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# SPDX-License-Identifier: MIT

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