feat: test middleware; use zoneinfo; fix datetime warnings

This commit is contained in:
bkfox
2023-08-23 15:08:20 +02:00
parent 02a8bb7a4e
commit 43c2d552e4
11 changed files with 53 additions and 36 deletions

View File

@@ -1,6 +1,6 @@
import calendar
import zoneinfo
import pytz
from django.db import models
from django.utils import timezone as tz
from django.utils.functional import cached_property
@@ -49,9 +49,9 @@ class Schedule(Rerun):
)
timezone = models.CharField(
_("timezone"),
default=lambda: tz.get_current_timezone().zone,
default=lambda: tz.get_current_timezone().key,
max_length=100,
choices=[(x, x) for x in pytz.all_timezones],
choices=[(x, x) for x in zoneinfo.available_timezones()],
help_text=_("timezone used for the date"),
)
duration = models.TimeField(
@@ -82,9 +82,7 @@ class Schedule(Rerun):
@cached_property
def tz(self):
"""Pytz timezone of the schedule."""
import pytz
return pytz.timezone(self.timezone)
return zoneinfo.ZoneInfo(self.timezone)
@cached_property
def start(self):
@@ -110,7 +108,7 @@ class Schedule(Rerun):
"""Return a datetime set to schedule's time for the provided date,
handling timezone (based on schedule's timezone)."""
date = tz.datetime.combine(date, self.time)
return self.tz.normalize(self.tz.localize(date))
return date.replace(tzinfo=self.tz)
def dates_of_month(self, date):
"""Return normalized diffusion dates of provided date's month."""