Skip to content

Commit

Permalink
Reverse humanize (#965)
Browse files Browse the repository at this point in the history
* changes

* Added test cases

* Added more langauges

* Added more langauge test cases and simplified code

* fixed merge issue with locales.py

* Added additional locales to test case files

* changes

* Added test cases

* Added more langauges

* Added more langauge test cases and simplified code

* fixed merge issue with locales.py

* Added additional locales to test case files

* Added comments as per style guide. Added more input validation and input validation test cases. Implemented fixes as per discussion.

* Fixed issue with failed Bengali test case

* Grammar errors in comments and error messages fixed.

* Added Dehumanize information to index.rst

* Edited Dehumaize documentation in index.rst to be more clear

* Fixed linting issue with docs

* Updated error in the documentation, as well as changed value error strings to format better

* Fixed typo in dehumanize doc

* White space error fixed
  • Loading branch information
anishnya authored Apr 28, 2021
1 parent fbec661 commit 08705bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,14 +1312,14 @@ def dehumanize(self, timestring: str, locale: str = "en_us") -> "Arrow":
>>> arw = arrow.utcnow()
>>> arw
<Arrow [2021-04-20T22:27:34.787885+00:00]>
>>> earlier = arw.dehumanize("two days ago")
>>> earlier = arw.dehumanize("2 days ago")
>>> earlier
<Arrow [2021-04-18T22:27:34.787885+00:00]>
>>> arw = arrow.utcnow()
>>> arw
<Arrow [2021-04-20T22:27:34.787885+00:00]>
>>> later = arw.dehumanize("in 1 month")
>>> later = arw.dehumanize("in a month")
>>> later
<Arrow [2021-05-18T22:27:34.787885+00:00]>
Expand Down Expand Up @@ -1393,8 +1393,8 @@ def dehumanize(self, timestring: str, locale: str = "en_us") -> "Arrow":
# Assert error if string does not modify any units
if not any([True for k, v in unit_visited.items() if v]):
raise ValueError(
"""Input string not valid. Note: Some locales do not support the week granulairty in Arrow.
If you are attempting to use the week granularity on an unsupported locale, this could be the cause of this error."""
"Input string not valid. Note: Some locales do not support the week granulairty in Arrow. "
"If you are attempting to use the week granularity on an unsupported locale, this could be the cause of this error."
)

# Sign logic
Expand All @@ -1418,9 +1418,9 @@ def dehumanize(self, timestring: str, locale: str = "en_us") -> "Arrow":
sign_val = 0
else:
raise ValueError(
"""Invalid input String. String does not contain any relative time information.
String should either represent a time in the future or a time in the past.
Ex: "in 5 seconds" or "5 seconds ago". """
"Invalid input String. String does not contain any relative time information. "
"String should either represent a time in the future or a time in the past. "
"Ex: 'in 5 seconds' or '5 seconds ago'."
)

time_changes = {k: sign_val * v for k, v in time_object_info.items()}
Expand Down
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ Take a human readable string and use it to shift into a past time:
>>> arw = arrow.utcnow()
>>> arw
<Arrow [2021-04-20T22:27:34.787885+00:00]>
>>> earlier = arw.dehumanize("two days ago")
>>> earlier = arw.dehumanize("2 days ago")
>>> earlier
<Arrow [2021-04-18T22:27:34.787885+00:00]>
Expand All @@ -273,7 +273,7 @@ Or use it to shift into a future time:
>>> arw = arrow.utcnow()
>>> arw
<Arrow [2021-04-20T22:27:34.787885+00:00]>
>>> later = arw.dehumanize("in 1 month")
>>> later = arw.dehumanize("in a month")
>>> later
<Arrow [2021-05-18T22:27:34.787885+00:00]>
Expand Down

0 comments on commit 08705bc

Please sign in to comment.