From 87d641d6c2a0695662c9b6861eb95c29301fe9a1 Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Mon, 6 Mar 2017 21:57:48 +0100 Subject: [PATCH] Replace native datetimes in the Codebase integration. Update all utcnow() and now() calls, as well as other native dates to specify the UTC timezone. Fixes #3809. --- integrations/codebase/zulip_codebase_mirror | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/integrations/codebase/zulip_codebase_mirror b/integrations/codebase/zulip_codebase_mirror index 4cad0c4..c109f15 100755 --- a/integrations/codebase/zulip_codebase_mirror +++ b/integrations/codebase/zulip_codebase_mirror @@ -33,6 +33,7 @@ from __future__ import print_function from __future__ import absolute_import import requests import logging +import pytz import time import sys import os @@ -269,7 +270,7 @@ def run_mirror(): # in check_permissions, but it may still be empty or corrupted def default_since(): # type: () -> datetime - return datetime.utcnow() - timedelta(hours=config.CODEBASE_INITIAL_HISTORY_HOURS) + return datetime.now(tz=pytz.utc) - timedelta(hours=config.CODEBASE_INITIAL_HISTORY_HOURS) try: with open(config.RESUME_FILE) as f: @@ -277,7 +278,7 @@ def run_mirror(): if timestamp == '': since = default_since() else: - since = datetime.fromtimestamp(float(timestamp)) + since = datetime.fromtimestamp(float(timestamp), tz=pytz.utc) except (ValueError, IOError) as e: logging.warn("Could not open resume file: %s" % (str(e))) since = default_since() @@ -290,7 +291,7 @@ def run_mirror(): sleepInterval = 1 for event in events: timestamp = event.get('event', {}).get('timestamp', '') - event_date = dateutil.parser.parse(timestamp).replace(tzinfo=None) + event_date = dateutil.parser.parse(timestamp) if event_date > since: handle_event(event) since = event_date