diff --git a/arrow/arrow.py b/arrow/arrow.py index eecf2326..99d006f1 100644 --- a/arrow/arrow.py +++ b/arrow/arrow.py @@ -1378,6 +1378,24 @@ def dehumanize(self, input_string: str, locale: str = "en_us") -> "Arrow": f"Dehumanize does not currently support the {locale} locale, please consider making a contribution to add support for this locale." ) + # A humanized string carries its direction in the "ago"/"in" wording, so + # a sign on the number is never meaningful. The number pattern below + # matches unsigned digits only, which would silently drop the sign and + # return a time shifted the opposite way. No locale's timeframe strings + # contain a hyphen, so one in front of a digit can only have come from + # the caller. + # + # A hyphen *between* digits is a separator, not a sign: "2020-01-01" is + # invalid input, but it is not a negative number, and saying so would send + # the caller looking for a sign that is not there. The lookbehind leaves + # those to the ordinary "not a valid humanized string" error below. + if re.search(r"(?