dehumanize() silently ignores negative time values, returning wrong results
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 74/100
Research direction
Start by searching the Python source for the dehumanize() entry point and the internal number-extraction regex described in the issue. Review the existing dehumanize tests, then verify that inputs containing negative numbers raise ValueError while valid relative time strings retain their current behavior.
Written by the indexing model from the issue text.
Description
What happened
While using dehumanize() to parse user-provided relative time strings, I noticed that negative values like "in -1 hours" don't raise an error - they silently produce the same result as "in 1 hours". The minus sign is dropped without any warning.
This is because the internal number-extraction regex \d+ only matches unsigned digits, so the - in -1 is never captured. The result is a quietly wrong datetime that's in the opposite direction from what a user might expect.
How to reproduce
import arrow
now = arrow.now()
# These two return the exact same result (+1 hour):
result1 = now.dehumanize("in 1 hours")
result2 = now.dehumanize("in -1 hours")
print((result1 - now).total_seconds()) # 3600.0
print((result2 - now).total_seconds()) # 3600.0 <- should not be the same!
Similarly, "in -2 days" silently becomes +2 days, and "-3 minutes ago" silently becomes -3 minutes (dropping the sign).
Expected behavior
dehumanize() should raise a ValueError when the input contains a negative number, since humanized time strings use "ago"/"in" for direction - not arithmetic signs. Silently swallowing the sign leads to wrong results that are hard to debug.
Version
arrow 1.4.0
Python 3.12
Windows 11
- Dominant language
- Python
- Stars
- 9.1k
- Forks
- 790
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from arrow-py/arrow
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100