View Single Post
Old 07-07-2025, 07:40 AM   #370
targosh
Junior Member
targosh began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Aug 2021
Device: Kobo Forma
Template Error

I am getting a template error for the time spent read column but am unsure why? Anyone has any ideas?

Quote:
Originally Posted by Majutsushi View Post
Time Spent Reading / Rest of Book Estimate formatting

If you want to show the "Time Spent Reading" and "Rest of Book Estimate" values in anything other than seconds, you will have to create two new columns that are based on the "seconds" columns and format the value differently.

Here is how you can do this:
  • Open the Calibre preferences.
  • Click on "Add your own columns".
  • Click on "Add custom column" or the green "+" sign on the right.
  • Enter a lookup name, like "#my_time_spent_reading".
  • Enter a column heading, like "Time Spent Reading".
  • For column type, choose "Column built from other columns".
  • Right-click in the "Template" entry field and click "Open template editor".
  • Enter the code to format the seconds to something else.

    Here is an example:
    Code:
    program:
    
    total = $#kobo_time_spent_reading;
    hours = floor(total/3600);
    minutes = round((total-hours*3600)/60);
    
    def format(v, str):
        if v == 0 then return '' fi;
        return v & ' ' & str & ' '
    fed;
    format(hours, 'hr') & format(minutes, 'min')
    This will format the time as something like "3 hr 27 min".

    Make sure to replace "#kobo_time_spent_reading" with the actual lookup name of the seconds column you want to reference.
  • Press "OK"/"Apply" to close all the dialogs and restart Calibre.
For more information about writing such a template check out https://manual.calibre-ebook.com/template_lang.html.
targosh is offline   Reply With Quote