Search code examples
javascriptpythonjquerytimetablesorter

Convert Python 'min:sec' string into a time object that looks the same, needs to be sorted properly by jQuery tablesorter


For some reason, tablesorter works properly only on strings that represents time lower than '25:00'. It's putting anything above '25:00' lower than '24:12' or '09:24' for example. So I probably need to convert the string to a time format. To be able to use col-index: { sorter: 'time'} in the tablesorter.

This is how it looks now

This is how it looks now

I've read datetime and time docs, found some great answers on SO, but couldn't find exactly what I need.

The closest I get is:

from datetime import datetime

datetime_object = datetime.strptime('12:55', '%M:%S')

print(datetime_object)

>>> 1900-01-01 00:12:55

Solution

  • If you're using my fork of tablesorter, there is an additional countdown parser. Load the parser-duration.js file and set the sorter to "countdown".