Change timezone-naive datetimes to use timezone.now() where safe to do so.

Change timezone-naive datetimes to use timezone.now() in cases where there
is no change in behavior.
This commit is contained in:
Rishi Gupta 2017-02-25 19:58:25 -08:00 committed by Tim Abbott
parent c388858e53
commit 3d07ac0c49
3 changed files with 9 additions and 6 deletions

View File

@ -18,6 +18,7 @@ sys.path.append('/home/zulip/deployments/current')
import scripts.lib.setup_path_on_import
import django
from django.utils import timezone
os.environ['DJANGO_SETTINGS_MODULE'] = "zproject.settings"
sys.path.append('/home/zulip/deployments/current')
@ -50,13 +51,13 @@ def report(state, short_msg, too_old=None):
exit(states[state])
now = datetime.datetime.utcnow()
now = timezone.now()
all_users = UserActivity.objects.filter(query__in=["get_events_backend", "/api/v1/events"],
client__name="zephyr_mirror")
new_inactive_users = [user for user in all_users if user.last_visit.replace(tzinfo=None) <
new_inactive_users = [user for user in all_users if user.last_visit <
now - datetime.timedelta(minutes=10)]
old_inactive_users = [user for user in new_inactive_users if user.last_visit.replace(tzinfo=None) <
old_inactive_users = [user for user in new_inactive_users if user.last_visit <
now - datetime.timedelta(minutes=60)]
recently_inactive_users = set(new_inactive_users) - set(old_inactive_users)

View File

@ -1,5 +1,7 @@
from __future__ import absolute_import
from django.utils import timezone
import hashlib
import logging
import traceback
@ -38,10 +40,10 @@ class _RateLimitFilter(object):
if not duplicate:
cache.set(key, 1, rate)
else:
min_date = datetime.now() - timedelta(seconds=rate)
min_date = timezone.now() - timedelta(seconds=rate)
duplicate = (self.last_error >= min_date)
if not duplicate:
self.last_error = datetime.now()
self.last_error = timezone.now()
return not duplicate

View File

@ -94,7 +94,7 @@ in a while.
# To be really conservative while we don't have user timezones or
# special-casing for companies with non-standard workweeks, only
# try to send mail on Tuesdays, Wednesdays, and Thursdays.
if datetime.datetime.utcnow().weekday() not in VALID_DIGEST_DAYS:
if timezone.now().weekday() not in VALID_DIGEST_DAYS:
return
deployment_realms = realms_for_this_deployment()