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.
This commit is contained in:
parent
7c3a228450
commit
87d641d6c2
|
@ -33,6 +33,7 @@ from __future__ import print_function
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import requests
|
import requests
|
||||||
import logging
|
import logging
|
||||||
|
import pytz
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
@ -269,7 +270,7 @@ def run_mirror():
|
||||||
# in check_permissions, but it may still be empty or corrupted
|
# in check_permissions, but it may still be empty or corrupted
|
||||||
def default_since():
|
def default_since():
|
||||||
# type: () -> datetime
|
# 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:
|
try:
|
||||||
with open(config.RESUME_FILE) as f:
|
with open(config.RESUME_FILE) as f:
|
||||||
|
@ -277,7 +278,7 @@ def run_mirror():
|
||||||
if timestamp == '':
|
if timestamp == '':
|
||||||
since = default_since()
|
since = default_since()
|
||||||
else:
|
else:
|
||||||
since = datetime.fromtimestamp(float(timestamp))
|
since = datetime.fromtimestamp(float(timestamp), tz=pytz.utc)
|
||||||
except (ValueError, IOError) as e:
|
except (ValueError, IOError) as e:
|
||||||
logging.warn("Could not open resume file: %s" % (str(e)))
|
logging.warn("Could not open resume file: %s" % (str(e)))
|
||||||
since = default_since()
|
since = default_since()
|
||||||
|
@ -290,7 +291,7 @@ def run_mirror():
|
||||||
sleepInterval = 1
|
sleepInterval = 1
|
||||||
for event in events:
|
for event in events:
|
||||||
timestamp = event.get('event', {}).get('timestamp', '')
|
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:
|
if event_date > since:
|
||||||
handle_event(event)
|
handle_event(event)
|
||||||
since = event_date
|
since = event_date
|
||||||
|
|
Loading…
Reference in a new issue