|
1 | 1 | import html |
2 | | -from datetime import datetime, timedelta, timezone |
| 2 | +from datetime import timedelta |
3 | 3 |
|
4 | 4 | from django.conf import settings |
5 | 5 | from django.contrib.auth.models import User |
6 | 6 | from django.core.management.base import BaseCommand |
7 | 7 | from django.db.models import DurationField, ExpressionWrapper, F, Q, Sum |
8 | 8 | from django.db.models.query import QuerySet |
9 | 9 | from django.template.loader import render_to_string |
| 10 | +from django.utils import timezone as dj_timezone |
10 | 11 | from django.utils.html import strip_tags |
11 | 12 | from elasticsearch.helpers import bulk |
12 | 13 | from sentry_sdk.crons import monitor |
@@ -80,23 +81,23 @@ class Command(BaseCommand): |
80 | 81 |
|
81 | 82 | # Digest mode duration is 5 minutes once a week |
82 | 83 | def is_digest_mode(self): |
83 | | - today = datetime.now(timezone.utc) |
| 84 | + today = dj_timezone.now() |
84 | 85 | weekdayhourmin = int(today.strftime("%w%H%M")) |
85 | 86 | return digest_time <= weekdayhourmin and weekdayhourmin < digest_time + 5 |
86 | 87 |
|
87 | 88 | def is_daily_checkup_time(self): |
88 | | - today = datetime.now(timezone.utc) |
| 89 | + today = dj_timezone.now() |
89 | 90 | hourmin = int(today.strftime("%H%M")) |
90 | 91 | return daily_retro <= hourmin and hourmin < daily_retro + 5 |
91 | 92 |
|
92 | 93 | def diff_9_minutes(self): |
93 | | - return datetime.now(timezone.utc) - time_9_minutes |
| 94 | + return dj_timezone.now() - time_9_minutes |
94 | 95 |
|
95 | 96 | def diff_1_day(self): |
96 | | - return datetime.now(timezone.utc) - time_1_day |
| 97 | + return dj_timezone.now() - time_1_day |
97 | 98 |
|
98 | 99 | def diff_1_week(self): |
99 | | - return datetime.now(timezone.utc) - time_1_week |
| 100 | + return dj_timezone.now() - time_1_week |
100 | 101 |
|
101 | 102 | def gather_country_and_region(self, records): |
102 | 103 | # Appeals only, since these have a single country/region |
@@ -345,7 +346,7 @@ def get_record_display(self, rtype, count): |
345 | 346 | return display |
346 | 347 |
|
347 | 348 | def get_weekly_digest_data(self, field): |
348 | | - today = datetime.now(timezone.utc) |
| 349 | + today = dj_timezone.now() |
349 | 350 | if field == "dref": |
350 | 351 | return Appeal.objects.filter(end_date__gt=today, atype=0).count() |
351 | 352 | elif field == "ea": |
|
0 commit comments