From 18d451974d7c5d12578696d27f04cb0a64332bbb Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sun, 29 Jul 2012 00:20:34 -0400 Subject: [PATCH] Store time data as actual datetime objects instead of UNIX time. --- earwigbot/tasks/afc_statistics.py | 2 +- earwigbot/tasks/drn_clerkbot.py | 20 ++++++++++++-------- earwigbot/tasks/schema/drn_clerkbot.sql | 8 ++++---- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/earwigbot/tasks/afc_statistics.py b/earwigbot/tasks/afc_statistics.py index 8fbe03d..55444d6 100644 --- a/earwigbot/tasks/afc_statistics.py +++ b/earwigbot/tasks/afc_statistics.py @@ -723,7 +723,7 @@ class AFCStatistics(Task): if "D" in statuses and chart != self.CHART_MISPLACE: notes += "|nr=1" # Submission was resubmitted - time_since_modify = (datetime.now() - m_time).total_seconds() + time_since_modify = (datetime.utcnow() - m_time).total_seconds() max_time = 4 * 24 * 60 * 60 if time_since_modify > max_time: notes += "|no=1" # Submission hasn't been touched in over 4 days diff --git a/earwigbot/tasks/drn_clerkbot.py b/earwigbot/tasks/drn_clerkbot.py index a885fa4..426916d 100644 --- a/earwigbot/tasks/drn_clerkbot.py +++ b/earwigbot/tasks/drn_clerkbot.py @@ -197,8 +197,9 @@ class DRNClerkBot(Task): f_time = datetime.strptime(strp, match.group(2)) else: f_user, f_time = None, datetime.utcnow() + zero = datetime.min case = _Case(id_, title, status, self.STATUS_UNKNOWN, f_user, - f_time, "", 0, "", 0, 0, False, False, 0, + f_time, "", zero, "", zero, zero, False, False, 0, new=True) cases.append(case) else: @@ -287,7 +288,8 @@ class DRNClerkBot(Task): if case.last_action != self.STATUS_NEEDASSIST: case.status = self.STATUS_NEEDASSIST timestamps = [timestamp for (editor, timestamp) in signatures] - if time() - max(timestamps) > 60 * 60 * 24 * 2: + age = (datetime.utcnow() - max(timestamps)).total_seconds() + if age > 60 * 60 * 24 * 2: if case.last_action != self.STATUS_STALE: case.status = self.STATUS_STALE return [] @@ -307,7 +309,8 @@ class DRNClerkBot(Task): return [] def clerk_review_case(self, case): - if time() - case.file_time > 60 * 60 * 24 * 7: + age = (datetime.utcnow() - case.file_time).total_seconds() + if age > 60 * 60 * 24 * 7: if not case.very_old_notified: template = "{{subst:" + self.tl_notify_stale template += case.title.replace("|", "|") + "}}" @@ -318,11 +321,11 @@ class DRNClerkBot(Task): def clerk_closed_case(self, case, signatures): if not case.close_time: - case.close_time = time() + case.close_time = datetime.utcnow() timestamps = [timestamp for (editor, timestamp) in signatures] - closed_long_ago = time() - case.close_time > 60 * 60 * 24 - modified_long_ago = time() - max(timestamps) > 60 * 60 * 24 - if closed_long_ago and modified_long_ago: + close_age = (datetime.utcnow() - case.close_time).total_seconds() + modify_age = (datetime.utcnow() - max(timestamps)).total_seconds() + if closed_age > 60 * 60 * 24 and modify_age > 60 * 60 * 24: case.status = self.STATUS_ARCHIVE case.body = "{{" + self.tl_archive_top + "}}\n" + case.body case.body += "\n{{" + self.tl_archive_bottom + "}}" @@ -330,7 +333,8 @@ class DRNClerkBot(Task): case.body = re.sub(reg, "", case.body) def check_for_review(self, case): - if time() - case.file_time > 60 * 60 * 24 * 4: + age = (datetime.utcnow() - case.file_time).total_seconds() + if age > 60 * 60 * 24 * 4: if case.last_action != self.STATUS_REVIEW: case.status = self.STATUS_REVIEW diff --git a/earwigbot/tasks/schema/drn_clerkbot.sql b/earwigbot/tasks/schema/drn_clerkbot.sql index 0bbca97..ff64927 100644 --- a/earwigbot/tasks/schema/drn_clerkbot.sql +++ b/earwigbot/tasks/schema/drn_clerkbot.sql @@ -19,12 +19,12 @@ CREATE TABLE `case` ( `case_status` int(2) unsigned DEFAULT NULL, `case_last_action` int(2) unsigned DEFAULT NULL, `case_file_user` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL, - `case_file_time` int(10) unsigned DEFAULT NULL, + `case_file_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `case_modify_user` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL, - `case_modify_time` int(10) unsigned DEFAULT NULL, + `case_modify_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `case_volunteer_user` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL, - `case_volunteer_time` int(10) unsigned DEFAULT NULL, - `case_close_time` int(10) unsigned DEFAULT NULL, + `case_volunteer_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `case_close_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `case_parties_notified` tinyint(1) unsigned DEFAULT NULL, `case_very_old_notified` tinyint(1) unsigned DEFAULT NULL, `case_last_volunteer_size` int(9) unsigned DEFAULT NULL,