From a4683c6b4c613392683d67af4c1a42a22d6619f9 Mon Sep 17 00:00:00 2001 From: Andy Date: Sun, 18 Sep 2022 18:58:41 -0400 Subject: [PATCH] Added explicit checking for type-comparison validity --- GTG/plugins/untouched_tasks/untouchedTasks.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/GTG/plugins/untouched_tasks/untouchedTasks.py b/GTG/plugins/untouched_tasks/untouchedTasks.py index dbae0cd6fc..1a9290354f 100644 --- a/GTG/plugins/untouched_tasks/untouchedTasks.py +++ b/GTG/plugins/untouched_tasks/untouchedTasks.py @@ -1,4 +1,3 @@ - # Copyright (c) 2012 - Tom Kadwill # # This program is free software: you can redistribute it and/or modify it under @@ -26,7 +25,6 @@ class UntouchedTasksPlugin(): - DEFAULT_PREFERENCES = {'max_days': 30, 'is_automatic': False, 'default_tag': 'untouched'} @@ -51,11 +49,11 @@ def __init__(self): self.builder.get_object("pref_tag_name") SIGNAL_CONNECTIONS_DIC = { "on_preferences_dialog_delete_event": - self.on_preferences_cancel, + self.on_preferences_cancel, "on_btn_preferences_cancel_clicked": - self.on_preferences_cancel, + self.on_preferences_cancel, "on_btn_preferences_ok_clicked": - self.on_preferences_ok, + self.on_preferences_ok, } self.builder.connect_signals(SIGNAL_CONNECTIONS_DIC) @@ -80,7 +78,7 @@ def deactivate(self, plugin_api): """ plugin_api.remove_menu_item(self.menu_item) -# CORE FUNCTIONS ############################################################## + # CORE FUNCTIONS ############################################################## def schedule_autopurge(self): self.timer = Timer(self.TIME_BETWEEN_PURGES, self.add_untouched_tag) @@ -110,7 +108,11 @@ def add_untouched_tag(self, action=None, param=None): # Add untouched tag to all tasks where new_date < time now for task in closed_tasks: modified_time = task.get_modified() + # get_modified might return a gtg.core.Date or a datetime.datetime. The validity of the comparison depends + # on which one we get, so check explicitly. This should probably be fixed in Task, eventually. new_time = modified_time + datetime.timedelta(days=max_days) + if type(new_time) == datetime.datetime: + new_time = new_time.date() if new_time < today: log.debug('Adding %r tag to: %r as last time it was modified ' 'was %r', tag_name, task.get_title(), modified_time) @@ -120,7 +122,7 @@ def add_untouched_tag(self, action=None, param=None): if self.is_automatic: self.schedule_autopurge() -# Preferences methods ######################################################### + # Preferences methods ######################################################### def is_configurable(self): """A configurable plugin should have this method and return True""" return True