Skip to content

Commit

Permalink
Makes the only_distance paramter value equivalent to value given to f…
Browse files Browse the repository at this point in the history
…unction when granularity paramter is also provided by user
  • Loading branch information
nishant jain authored and nishant jain committed Dec 10, 2017
1 parent 66ac193 commit 0f60d3d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def humanize(self, other=None, locale='en_us', only_distance=False, granularity=

if(trunc(abs(delta)) != 1):
granularity += 's'
return locale.describe(granularity, delta, only_distance=False)
return locale.describe(granularity, delta, only_distance=only_distance)
# math

def __add__(self, other):
Expand Down
4 changes: 4 additions & 0 deletions tests/arrow_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,10 @@ def test_granularity(self):
later108 = self.now.shift(seconds=10 ** 8)
assertEqual(self.now.humanize(later108, granularity = 'year'), '3 years ago')
assertEqual(later108.humanize(self.now, granularity = 'year'), 'in 3 years')

later108onlydistance = self.now.shift(seconds=10 ** 8)
assertEqual(self.now.humanize(later108onlydistance , only_distance=True, granularity = 'year'), '3 years')
assertEqual(later108onlydistance .humanize(self.now, only_distance=True, granularity = 'year'), '3 years')
with assertRaises(AttributeError):
self.now.humanize(later108, granularity = 'years')

Expand Down

0 comments on commit 0f60d3d

Please sign in to comment.