MCPcopy
hub / github.com/django/django / _sqlite_datetime_parse

Function _sqlite_datetime_parse

django/db/backends/sqlite3/_functions.py:119–138  ·  view source on GitHub ↗
(dt, tzname=None, conn_tzname=None)

Source from the content-addressed store, hash-verified

117
118
119def _sqlite_datetime_parse(dt, tzname=None, conn_tzname=None):
120 if dt is None:
121 return None
122 try:
123 dt = typecast_timestamp(dt)
124 except (TypeError, ValueError):
125 return None
126 if conn_tzname:
127 dt = dt.replace(tzinfo=zoneinfo.ZoneInfo(conn_tzname))
128 if tzname is not None and tzname != conn_tzname:
129 tzname, sign, offset = split_tzname_delta(tzname)
130 if offset:
131 hours, minutes = offset.split(":")
132 offset_delta = timedelta(hours=int(hours), minutes=int(minutes))
133 dt += offset_delta if sign == "+" else -offset_delta
134 # The tzname may originally be just the offset e.g. "+3:00",
135 # which becomes an empty string after splitting the sign and offset.
136 # In this case, use the conn_tzname as fallback.
137 dt = timezone.localtime(dt, zoneinfo.ZoneInfo(tzname or conn_tzname))
138 return dt
139
140
141def _sqlite_date_trunc(lookup_type, dt, tzname, conn_tzname):

Callers 6

_sqlite_date_truncFunction · 0.85
_sqlite_time_truncFunction · 0.85
_sqlite_datetime_extractFunction · 0.85
_sqlite_datetime_truncFunction · 0.85

Calls 3

typecast_timestampFunction · 0.90
split_tzname_deltaFunction · 0.90
splitMethod · 0.45

Tested by

no test coverage detected