Merge pull request #16 from Ensiss/sort-fix

Fix sort by age
pull/20/head
Jake Funke 2018-06-12 17:05:35 -07:00 committed by GitHub
commit 93c8656c55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -294,7 +294,17 @@ class CursedMenu(object):
def sort_garden_table(self, table, column, ascending): def sort_garden_table(self, table, column, ascending):
""" Sort table in place by a specified column """ """ 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): def filter_garden_table(self, table, pattern):
""" Filter table using a pattern, and return the new table """ """ Filter table using a pattern, and return the new table """