Skip to content

Commit 6b991e6

Browse files
committed
Changes to for_humans() of the interval class to in_words()
1 parent 4580aef commit 6b991e6

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

docs/index.rst

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,27 @@ you can use the appropriate methods.
10861086
it.total_seconds()
10871087
101700084.001234
10881088
1089-
It also has a handy ``for_humans()``, which determines the interval representation when printed,
1090-
that prints the interval for humans.
1089+
Similarly, it has the ``in_xxx()`` methods which returns to total duration in each
1090+
supported unit as a truncated integer.
1091+
1092+
.. code-block:: python
1093+
1094+
it.in_weeks()
1095+
168
1096+
1097+
it.in_days()
1098+
1177
1099+
1100+
it.in_hours()
1101+
28250
1102+
1103+
it.in_minutes()
1104+
1695001
1105+
1106+
it.in_seconds()
1107+
101700084
1108+
1109+
It also has a handy ``in_words()``, which determines the interval representation when printed.
10911110

10921111
.. code-block:: python
10931112
@@ -1098,11 +1117,11 @@ that prints the interval for humans.
10981117
10991118
it = pendulum.interval(days=1177, seconds=7284, microseconds=1234)
11001119
1101-
it.for_humans()
1120+
it.in_words()
11021121
'168 semaines 1 jour 2 heures 1 minute 24 secondes'
11031122
11041123
print(it)
11051124
'168 semaines 1 jour 2 heures 1 minute 24 secondes'
11061125
1107-
it.for_humans(locale='de')
1126+
it.in_words(locale='de')
11081127
'168 Wochen 1 Tag 2 Stunden 1 Minute 24 Sekunden'

pendulum/pendulum_interval.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,11 @@ def _sign(self, value):
199199

200200
return 1
201201

202-
def for_humans(self, locale=None):
202+
def in_words(self, locale=None):
203203
"""
204-
Get the current interval in a human readable format
205-
in the current locale.
204+
Get the current interval in words in the current locale.
205+
206+
Ex: 6 jours 23 heures 58 minutes
206207
207208
:rtype: str
208209
"""
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ def setUp(self):
1313
PendulumInterval.set_locale('en')
1414

1515
def test_week(self):
16-
self.assertEqual('52 weeks', PendulumInterval(days=364).for_humans())
16+
self.assertEqual('52 weeks', PendulumInterval(days=364).in_words())
1717
self.assertEqual('1 week', PendulumInterval(days=7).for_humans())
1818

1919
def test_week_to_string(self):
2020
self.assertEqual('52 weeks', str(PendulumInterval(days=364)))
2121
self.assertEqual('1 week', str(PendulumInterval(days=7)))
2222

2323
def test_weeks_and_day(self):
24-
self.assertEqual('52 weeks 1 day', PendulumInterval(days=365).for_humans())
24+
self.assertEqual('52 weeks 1 day', PendulumInterval(days=365).in_words())
2525

2626
def test_all(self):
2727
pi = PendulumInterval(days=1177, seconds=7284, microseconds=1000000)
2828
self.assertEqual(
2929
'168 weeks 1 day 2 hours 1 minute 25 seconds',
30-
pi.for_humans()
30+
pi.in_words()
3131
)
3232

3333
def test_in_french(self):
3434
pi = PendulumInterval(days=1177, seconds=7284, microseconds=1000000)
3535
self.assertEqual(
3636
'168 semaines 1 jour 2 heures 1 minute 25 secondes',
37-
pi.for_humans(locale='fr')
37+
pi.in_words(locale='fr')
3838
)

0 commit comments

Comments
 (0)