arrow-py / arrow

🏹 Better dates & times for Python
https://arrow.readthedocs.io
Apache License 2.0
8.7k stars 673 forks source link

support dates like "next tuesday" #1100

Open anarcat opened 2 years ago

anarcat commented 2 years ago

Feature Request

It would be great if arrow supported more human-readable date specifications like "next tuesday" or "previous year"... This is something only parsedatetime does right now, as far as I know.

anarcat@curie:undertime(main)$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> arrow.__version__
'1.2.1'
>>> arrow.utcnow().dehumanize("next tuesday")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/arrow/arrow.py", line 1421, in dehumanize
    raise ValueError(
ValueError: Input string not valid. Note: Some locales do not support the week granulairty in Arrow. If you are attempting to use the week granularity on an unsupported locale, this could be the cause of this error.
>>> 
anishnya commented 2 years ago

This definitely is something we want to add going forward. #1081 would help making sure this has broad support beyond just English.

krisfremen commented 2 years ago

Indeed, cldr has most of the relative types for many languages.

This would mean a bit of a refactor and changes to the current locale setup to accommodate the layout of cldr as well.