Support cron presets in date_range function (#7777)
This commit is contained in:
Родитель
bed1995752
Коммит
b59adaba36
|
@ -70,6 +70,8 @@ def date_range(start_date, end_date=None, num=None, delta=None): # pylint: disa
|
|||
raise Exception("Wait. Either specify end_date OR num")
|
||||
if not end_date and not num:
|
||||
end_date = timezone.utcnow()
|
||||
if delta in cron_presets:
|
||||
delta = cron_presets.get(delta)
|
||||
|
||||
delta_iscron = False
|
||||
time_zone = start_date.tzinfo
|
||||
|
|
|
@ -94,3 +94,11 @@ class TestUtilsDatesDateRange(unittest.TestCase):
|
|||
|
||||
for i in range(num):
|
||||
self.assertTrue(timezone.is_localized(result[i]))
|
||||
|
||||
def test_delta_cron_presets(self):
|
||||
preset_range = dates.date_range(datetime(2016, 1, 1), num=2, delta="@hourly")
|
||||
timedelta_range = dates.date_range(datetime(2016, 1, 1), num=2, delta=timedelta(hours=1))
|
||||
cron_range = dates.date_range(datetime(2016, 1, 1), num=2, delta="0 * * * *")
|
||||
|
||||
self.assertEqual(preset_range, timedelta_range)
|
||||
self.assertEqual(preset_range, cron_range)
|
||||
|
|
Загрузка…
Ссылка в новой задаче