diff --git a/analytics/management/commands/active_user_stats.py b/analytics/management/commands/active_user_stats.py index ff09fa1f7e..82841ecddd 100644 --- a/analytics/management/commands/active_user_stats.py +++ b/analytics/management/commands/active_user_stats.py @@ -19,7 +19,7 @@ class Command(BaseCommand): def handle(self, *args, **options): # type: (*Any, **Any) -> None # Get list of all active users in the last 1 week - cutoff = datetime.now() - timedelta(minutes=30, hours=168) + cutoff = timezone.now() - timedelta(minutes=30, hours=168) users = UserPresence.objects.select_related().filter(timestamp__gt=cutoff) diff --git a/analytics/management/commands/client_activity.py b/analytics/management/commands/client_activity.py index 4f136dbb79..529a7d3889 100644 --- a/analytics/management/commands/client_activity.py +++ b/analytics/management/commands/client_activity.py @@ -6,6 +6,7 @@ from typing import Any from argparse import ArgumentParser from django.core.management.base import BaseCommand from django.db.models import Count, QuerySet +from django.utils import timezone from zerver.models import UserActivity, UserProfile, Realm, \ get_realm, get_user_profile_by_email @@ -38,7 +39,7 @@ Usage examples: # # Importantly, this does NOT tell you anything about the relative # volumes of requests from clients. - threshold = datetime.datetime.now() - datetime.timedelta(days=7) + threshold = timezone.now() - datetime.timedelta(days=7) client_counts = user_activity_objects.filter( last_visit__gt=threshold).values("client__name").annotate( count=Count('client__name')) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 25a12b2b85..8690ebf81c 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -445,7 +445,7 @@ def delete_realm_user_sessions(realm): # type: (Realm) -> None realm_user_ids = [user_profile.id for user_profile in UserProfile.objects.filter(realm=realm)] - for session in Session.objects.filter(expire_date__gte=datetime.datetime.now()): + for session in Session.objects.filter(expire_date__gte=timezone.now()): if get_session_user(session) in realm_user_ids: delete_session(session) diff --git a/zerver/management/commands/dump_messages.py b/zerver/management/commands/dump_messages.py index d9d13953ba..dbab10e674 100644 --- a/zerver/management/commands/dump_messages.py +++ b/zerver/management/commands/dump_messages.py @@ -5,6 +5,7 @@ from typing import Any from optparse import make_option from django.core.management.base import BaseCommand, CommandParser +from django.utils import timezone from zerver.models import get_realm, Message, Realm, Stream, Recipient import datetime @@ -31,7 +32,7 @@ class Command(BaseCommand): streams = Stream.objects.filter(realm=realm, invite_only=False) recipients = Recipient.objects.filter( type=Recipient.STREAM, type_id__in=[stream.id for stream in streams]) - cutoff = datetime.datetime.fromtimestamp(options["since"]) + cutoff = datetime.datetime.fromtimestamp(options["since"], tz=timezone.utc) messages = Message.objects.filter(pub_date__gt=cutoff, recipient__in=recipients) for message in messages: