Skip to content

Commit 335fc8c

Browse files
committed
Adds a separator keyword argument to Interval.in_words() method
1 parent 3e4d3e8 commit 335fc8c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pendulum/mixins/interval.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55

66
class WordableIntervalMixin(TranslatableMixin):
77

8-
def in_words(self, locale=None):
8+
def in_words(self, locale=None, separator=' '):
99
"""
1010
Get the current interval in words in the current locale.
1111
1212
Ex: 6 jours 23 heures 58 minutes
1313
14+
:param locale: The locale to use. Defaults to current locale.
15+
:type locale: str
16+
17+
:param separator: The separator to use between each unit
18+
:type separator: str
19+
1420
:rtype: str
1521
"""
1622
periods = [
@@ -29,7 +35,7 @@ def in_words(self, locale=None):
2935
self.translator().transchoice(unit, abs(count), {'count': count}, locale=locale)
3036
)
3137

32-
return ' '.join(parts)
38+
return separator.join(parts)
3339

3440
def __str__(self):
3541
return self.in_words()

tests/interval_tests/test_in_words.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ def test_singluar_negative_values(self):
5050
'-1 day',
5151
pi.in_words()
5252
)
53+
54+
def test_separator(self):
55+
pi = Interval(days=1177, seconds=7284, microseconds=1000000)
56+
self.assertEqual(
57+
'168 weeks, 1 day, 2 hours, 1 minute, 25 seconds',
58+
pi.in_words(separator=', ')
59+
)

0 commit comments

Comments
 (0)