arrow-py / arrow

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

The dehumanize method doesn't recognize singular nouns #1150

Open Ghost-Terms opened 1 year ago

Ghost-Terms commented 1 year ago

arrow.now().dehumanize("1 day ago").isoformat() doesn't work.

arrow.now().dehumanize("1 days ago").isoformat() does work.

Same with week, month, and year.

krisfremen commented 1 year ago

Looking at it, it seems like the dehumanize only supports the plurals.

@anishnya any insight on this one?

anishnya commented 1 year ago

We use the humanize output and reverse it for dehumanize.

arrow.now().dehumanize("a day ago").isoformat() will work since that's what humanize produces. Humanize doesn't ever produce the "1 days ago" output, hence we don't have that mapping in there.

We certainly could add this translation in for English, but ideally we would want similar mappings across all languages. I'm open to making this a broader issue and attempting to solve it.

ben-kenney commented 8 months ago

I came here looking for a solution to this issue.

arrow.now().dehumanize("1 hour ago").isoformat() throws the following error:

ValueError: Input string not valid. Note: Some locales do not support the week granularity in Arrow. If you are attempting to use the week granularity on an unsupported locale, this could be the cause of this error.

whereas arrow.now().dehumanize("1 hours ago").isoformat() does work but the plural hours doesn't make grammatical sense in this case.

davidgolden commented 2 months ago

@anishnya As @ben-kenney points out, your comment doesn't address the issue. While I can understand that 1 days ago might not be valid, 1 day ago should be, but the latter throws a ValueError.

Ghost-Terms commented 2 months ago

Yeah, it's worth pointing out again that dehumanize implies that the string is already humanized, but it's hard to say "1 days ago" is considered humanized.