Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,10 @@ def dehumanize(self, input_string: str, locale: str = "en_us") -> "Arrow":
search_string = str(time_string)
search_string = search_string.format(r"\d+")

# Make trailing 's' optional so both "1 day" and "2 days" match
if search_string.endswith("s"):
search_string = search_string[:-1] + "s?"

# Create search pattern and find within string
pattern = re.compile(rf"(^|\b|\d){search_string}")
match = pattern.search(input_string)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2987,6 +2987,21 @@ def test_czech_slovak(self):
assert arw.dehumanize(past_string, locale=lang) == past
assert arw.dehumanize(future_string, locale=lang) == future

def test_singular_units(self):
arw = arrow.Arrow(2023, 1, 1)

assert arw.dehumanize("1 day ago") == arw.shift(days=-1)
assert arw.dehumanize("1 hour ago") == arw.shift(hours=-1)
assert arw.dehumanize("1 minute ago") == arw.shift(minutes=-1)
assert arw.dehumanize("1 second ago") == arw.shift(seconds=-1)
assert arw.dehumanize("1 week ago") == arw.shift(weeks=-1)
assert arw.dehumanize("1 month ago") == arw.shift(months=-1)
assert arw.dehumanize("1 year ago") == arw.shift(years=-1)

assert arw.dehumanize("in 1 day") == arw.shift(days=1)
assert arw.dehumanize("in 1 hour") == arw.shift(hours=1)
assert arw.dehumanize("in 1 minute") == arw.shift(minutes=1)


class TestArrowIsBetween:
def test_start_before_end(self):
Expand Down
Loading