Download benchmark/python/py-relevant-naturaldate-timezone/hidden_oracle.py from RedinGhost/beforedone-paper: direct link, hf CLI and curl.
- Browser
- Download file 885 Bytes
-
https://huggingface.co/datasets/RedinGhost/beforedone-paper/resolve/main/benchmark/python/py-relevant-naturaldate-timezone/hidden_oracle.py
- Command line
-
hf download hf://datasets/RedinGhost/beforedone-paper/benchmark/python/py-relevant-naturaldate-timezone/hidden_oracle.py
-
curl -L -o hidden_oracle.py https://huggingface.co/datasets/RedinGhost/beforedone-paper/resolve/main/benchmark/python/py-relevant-naturaldate-timezone/hidden_oracle.py
885 Bytes
| # 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") | |