From 08705bcde7a8eef65a40f43acd733863d8c1f63b Mon Sep 17 00:00:00 2001 From: Anish Nyayachavadi <55898433+anishnya@users.noreply.github.com> Date: Tue, 27 Apr 2021 20:46:27 -0400 Subject: [PATCH] Reverse humanize (#965) * 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 --- arrow/arrow.py | 14 +++++++------- docs/index.rst | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arrow/arrow.py b/arrow/arrow.py index 515c0ab6..b962c656 100644 --- a/arrow/arrow.py +++ b/arrow/arrow.py @@ -1312,14 +1312,14 @@ def dehumanize(self, timestring: str, locale: str = "en_us") -> "Arrow": >>> arw = arrow.utcnow() >>> arw - >>> earlier = arw.dehumanize("two days ago") + >>> earlier = arw.dehumanize("2 days ago") >>> earlier >>> arw = arrow.utcnow() >>> arw - >>> later = arw.dehumanize("in 1 month") + >>> later = arw.dehumanize("in a month") >>> later @@ -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 @@ -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()} diff --git a/docs/index.rst b/docs/index.rst index 3cef5a9b..43895b04 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -262,7 +262,7 @@ Take a human readable string and use it to shift into a past time: >>> arw = arrow.utcnow() >>> arw - >>> earlier = arw.dehumanize("two days ago") + >>> earlier = arw.dehumanize("2 days ago") >>> earlier @@ -273,7 +273,7 @@ Or use it to shift into a future time: >>> arw = arrow.utcnow() >>> arw - >>> later = arw.dehumanize("in 1 month") + >>> later = arw.dehumanize("in a month") >>> later