sdispater / pendulum

Python datetimes made easy
https://pendulum.eustace.io
MIT License
6.12k stars 372 forks source link

Allow formatting of `in_words` #788

Open BrutuZ opened 6 months ago

BrutuZ commented 6 months ago

Feature Request

A format parameter in the in_words() function to allow limiting the units used.

Reasoning

Assuming a

dt = pendulum.duration(years=1, months=2, weeks=3, days=4, hours=5, minutes=6, seconds=7)

The current format for dt.in_words() (1 year 2 months 3 weeks 4 days 5 hours 6 minutes 7 seconds) can be too verbose for some use-cases where a more compact format would be more suitable, so I propose adding an optional format parameter for more granular control of units\fields. That way, if we call it like dt.in_words(format='YMD') we'd get 1 year 2 months 25 days, dt.in_words(format='MDm') would result in 14 months 25 days 306 minutes and so on