From 5288ead6b6a2f36e02e50dc1d45b9d7d1bae1656 Mon Sep 17 00:00:00 2001 From: Ensis Date: Wed, 6 Jun 2018 22:34:30 +0200 Subject: [PATCH] Fix sort by age --- menu_screen.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/menu_screen.py b/menu_screen.py index b05d572..939574e 100644 --- a/menu_screen.py +++ b/menu_screen.py @@ -294,7 +294,17 @@ class CursedMenu(object): def sort_garden_table(self, table, column, ascending): """ Sort table in place by a specified column """ - return table.sort(key=lambda x: x[column], reverse=not ascending) + def key(entry): + entry = entry[column] + # In when sorting ages, convert to seconds + if column == 1: + coeffs = [24*60*60, 60*60, 60, 1] + nums = [int(n[:-1]) for n in entry.split(":")] + if len(nums) == len(coeffs): + entry = sum(nums[i] * coeffs[i] for i in range(len(nums))) + return entry + + return table.sort(key=key, reverse=not ascending) def filter_garden_table(self, table, pattern): """ Filter table using a pattern, and return the new table """