Skip to content

Commit 5cf2bd1

Browse files
committed
rename zoneinfo and remove unnecessary conversions
1 parent d5abadd commit 5cf2bd1

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

django_celery_beat/schedulers.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,14 @@ def _get_crontab_exclude_query(self):
335335
# Handle each timezone specifically
336336
*[
337337
When(
338-
timezone=timezone_name,
338+
timezone=timezone,
339339
then=(
340340
F('hour_int')
341-
+ self._get_timezone_offset(timezone_name)
341+
+ self._get_timezone_offset(timezone)
342342
+ 24
343343
) % 24
344344
)
345-
for timezone_name in self._get_unique_timezones()
345+
for timezone in self._get_unique_timezones()
346346
],
347347
# Default case - use hour as is
348348
default=F('hour_int')
@@ -381,7 +381,7 @@ def _get_unique_timezones(self) -> set[ZoneInfo]:
381381
)
382382
)
383383

384-
def _get_timezone_offset(self, timezone_name):
384+
def _get_timezone_offset(self, timezone: ZoneInfo) -> int:
385385
"""
386386
Args:
387387
timezone_name: The name of the timezone or a ZoneInfo object
@@ -397,17 +397,12 @@ def _get_timezone_offset(self, timezone_name):
397397
else:
398398
server_tz = ZoneInfo(str(server_time.tzinfo))
399399

400-
if isinstance(timezone_name, ZoneInfo):
401-
timezone_name = timezone_name.key
402-
403-
target_tz = ZoneInfo(timezone_name)
404-
405400
# Use a fixed point in time for the calculation to avoid DST issues
406401
fixed_dt = datetime.datetime(2023, 1, 1, 12, 0, 0)
407402

408403
# Calculate the offset
409404
dt1 = fixed_dt.replace(tzinfo=server_tz)
410-
dt2 = fixed_dt.replace(tzinfo=target_tz)
405+
dt2 = fixed_dt.replace(tzinfo=timezone)
411406

412407
# Calculate hour difference
413408
offset_seconds = (

0 commit comments

Comments
 (0)