Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename zoneinfo and remove unnecessary conversions
  • Loading branch information
beedub committed May 18, 2025
commit d88ba8bc93ba8db8e672702f9b81a04c6f205652
15 changes: 5 additions & 10 deletions django_celery_beat/schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,14 @@ def _get_crontab_exclude_query(self):
# Handle each timezone specifically
*[
When(
timezone=timezone_name,
timezone=timezone,
Copy link

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lookup uses a ZoneInfo object for the timezone field, but the database stores timezones as strings. Convert to str(timezone) or timezone.key so the ORM lookup matches the stored values.

Suggested change
timezone=timezone,
timezone=str(timezone),

Copilot uses AI. Check for mistakes.
then=(
F('hour_int')
+ self._get_timezone_offset(timezone_name)
+ self._get_timezone_offset(timezone)
+ 24
) % 24
)
for timezone_name in self._get_unique_timezones()
for timezone in self._get_unique_timezones()
],
# Default case - use hour as is
default=F('hour_int')
Expand Down Expand Up @@ -387,7 +387,7 @@ def _get_unique_timezones(self) -> set[ZoneInfo]:
)
)

def _get_timezone_offset(self, timezone_name):
def _get_timezone_offset(self, timezone: ZoneInfo) -> int:
"""
Args:
timezone_name: The name of the timezone or a ZoneInfo object
Expand All @@ -403,17 +403,12 @@ def _get_timezone_offset(self, timezone_name):
else:
server_tz = ZoneInfo(str(server_time.tzinfo))

if isinstance(timezone_name, ZoneInfo):
timezone_name = timezone_name.key

target_tz = ZoneInfo(timezone_name)

# Use a fixed point in time for the calculation to avoid DST issues
fixed_dt = datetime.datetime(2023, 1, 1, 12, 0, 0)

# Calculate the offset
dt1 = fixed_dt.replace(tzinfo=server_tz)
dt2 = fixed_dt.replace(tzinfo=target_tz)
dt2 = fixed_dt.replace(tzinfo=timezone)

# Calculate hour difference
offset_seconds = (
Expand Down