1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #33037 -- Fixed Trunc() with offset timezones on MySQL, SQLite, Oracle.

This commit is contained in:
Shafiya Adzhani
2024-02-03 20:05:15 +07:00
committed by Mariusz Felisiak
parent 2aa8388110
commit 22285d366c
4 changed files with 36 additions and 16 deletions

View File

@@ -118,7 +118,10 @@ def _sqlite_datetime_parse(dt, tzname=None, conn_tzname=None):
hours, minutes = offset.split(":")
offset_delta = timedelta(hours=int(hours), minutes=int(minutes))
dt += offset_delta if sign == "+" else -offset_delta
dt = timezone.localtime(dt, zoneinfo.ZoneInfo(tzname))
# The tzname may originally be just the offset e.g. "+3:00",
# which becomes an empty string after splitting the sign and offset.
# In this case, use the conn_tzname as fallback.
dt = timezone.localtime(dt, zoneinfo.ZoneInfo(tzname or conn_tzname))
return dt

View File

@@ -200,6 +200,8 @@ def split_tzname_delta(tzname):
if sign in tzname:
name, offset = tzname.rsplit(sign, 1)
if offset and parse_time(offset):
if ":" not in offset:
offset = f"{offset}:00"
return name, sign, offset
return tzname, None, None