#1278·arrow

dehumanize() silently ignores negative time values, returning wrong results

Author: amanv0007Created May 17, 2026Updated May 17, 2026

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