mirror of https://github.com/zulip/zulip.git
populate_db: Import timedelta from its canonical module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
0628c3cac8
commit
aa577a554b
|
@ -1,4 +1,4 @@
|
|||
from django.utils.timezone import timedelta as timezone_timedelta
|
||||
from datetime import timedelta
|
||||
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zilencer.management.commands.populate_db import choose_date_sent
|
||||
|
@ -19,9 +19,7 @@ class TestChoosePubDate(ZulipTestCase):
|
|||
|
||||
# Verify there is a meaningful difference between elements.
|
||||
for i in range(1, len(datetimes_list)):
|
||||
self.assertTrue(
|
||||
datetimes_list[i] - datetimes_list[i - 1] > timezone_timedelta(minutes=5)
|
||||
)
|
||||
self.assertTrue(datetimes_list[i] - datetimes_list[i - 1] > timedelta(minutes=5))
|
||||
|
||||
|
||||
class TestUserTimeZones(ZulipTestCase):
|
||||
|
|
|
@ -2,7 +2,7 @@ import itertools
|
|||
import os
|
||||
import random
|
||||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any, Dict, List, Mapping, Sequence, Tuple
|
||||
|
||||
import bmemcached
|
||||
|
@ -16,7 +16,6 @@ from django.db import connection
|
|||
from django.db.models import F
|
||||
from django.db.models.signals import post_delete
|
||||
from django.utils.timezone import now as timezone_now
|
||||
from django.utils.timezone import timedelta as timezone_timedelta
|
||||
|
||||
from scripts.lib.zulip_tools import get_or_create_dev_uuid_var_path
|
||||
from zerver.actions.create_realm import do_create_realm
|
||||
|
@ -1223,7 +1222,7 @@ def choose_date_sent(
|
|||
amount_in_second_chunk = tot_messages - amount_in_first_chunk
|
||||
|
||||
if num_messages < amount_in_first_chunk:
|
||||
spoofed_date = timezone_now() - timezone_timedelta(days=oldest_message_days)
|
||||
spoofed_date = timezone_now() - timedelta(days=oldest_message_days)
|
||||
num_days_for_first_chunk = min(oldest_message_days - 2, 1)
|
||||
interval_size = num_days_for_first_chunk * 24 * 60 * 60 / amount_in_first_chunk
|
||||
lower_bound = interval_size * num_messages
|
||||
|
@ -1231,13 +1230,13 @@ def choose_date_sent(
|
|||
|
||||
else:
|
||||
# We're in the last 20% of messages, so distribute them over the last 24 hours:
|
||||
spoofed_date = timezone_now() - timezone_timedelta(days=1)
|
||||
spoofed_date = timezone_now() - timedelta(days=1)
|
||||
interval_size = 24 * 60 * 60 / amount_in_second_chunk
|
||||
lower_bound = interval_size * (num_messages - amount_in_first_chunk)
|
||||
upper_bound = interval_size * (num_messages - amount_in_first_chunk + 1)
|
||||
|
||||
offset_seconds = random.uniform(lower_bound, upper_bound)
|
||||
spoofed_date += timezone_timedelta(seconds=offset_seconds)
|
||||
spoofed_date += timedelta(seconds=offset_seconds)
|
||||
|
||||
return spoofed_date
|
||||
|
||||
|
|
Loading…
Reference in New Issue