Skip to content
Discussion options

You must be logged in to vote

For that representation, convert the duration to a standard datetime.timedelta with as_timedelta():

import pendulum

duration = pendulum.duration(minutes=6, seconds=58)
print(str(duration.as_timedelta()))
# 0:06:58

I checked this with Pendulum 3.2.0. str(duration) gives 6 minutes 58 seconds, while str(duration.as_timedelta()) gives the exact representation in your question. The implementation exposes the conversion and uses in_words() for the duration's own string representation.

This follows standard timedelta formatting: a 27-hour duration displays 1 day, 3:00:00, and fractional seconds are included when present. If you want total hours such as 27:00:00, that would need a custom format.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Exenifix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants