View Single Post
Old 07-08-2025, 09:57 PM   #374
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 47,053
Karma: 169810634
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by chaley View Post
FWIW: I've seen several posts over the years that discuss formatting a duration in seconds into some "human readable" string. I decided to add a template function.
Code:
format_duration(value, template, largest_unit)
that given a duration is seconds can produce things like "2 weeks 4 days 20 minutes". I'll post the documentation in the template changes thread if and when Kovid accepts the change.
For me, I've only once had a reading time go over 17 hours (and that was an omnibus with over 1 million words).

OTOH, your new function looks good for some of my other uses and is much appreciated compared to my current multi-line mess for converting seconds to other time units.

Edit: downloaded calibre source and the format_duration seems to be working okay for me where a book has been opened to read. I still need to play handling entries where the book has not been opened.

Last edited by DNSB; 07-09-2025 at 03:42 AM.
DNSB is offline   Reply With Quote