dehumanize() silently ignores negative time values, returning wrong results
- Dominant language
- Python
- Stars
- 9.1k
- Forks
- 784
- PR merge metrics
- No merged PRs in 30d
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
```python
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
```
Contributor guide
No contributing guide indexed for this repository
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.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 74/100