View Single Post
Old 07-08-2025, 05:35 PM   #373
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,450
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by DNSB View Post
As @chaley said, it would help if you posted what you used as the template and the column definition.

For what it may be worth, here's my variant which gives hours, minutes, seconds:

Code:
program:

	total = $#kobo_time_spent_reading;

	hours = floor(total/3600);
	minutes = floor(mod(total, 3600)/60);
	seconds = mod(total, 60);
	def format(v, str):
    if v == 0 then return '' fi;
    return v & ' ' & str & ' '
fed;
format(hours, 'hr') & format(minutes, 'min') & format(seconds, 'sec')
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.
chaley is offline   Reply With Quote