mirror of https://github.com/django/django.git
Made some date parsing in SQLite functions more DRY.
This commit is contained in:
parent
c49ea6f591
commit
af7a758dcb
|
@ -325,12 +325,21 @@ class SQLiteCursorWrapper(Database.Cursor):
|
||||||
return FORMAT_QMARK_REGEX.sub('?', query).replace('%%', '%')
|
return FORMAT_QMARK_REGEX.sub('?', query).replace('%%', '%')
|
||||||
|
|
||||||
|
|
||||||
def _sqlite_date_extract(lookup_type, dt):
|
def _sqlite_datetime_parse(dt, tzname=None):
|
||||||
if dt is None:
|
if dt is None:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
dt = backend_utils.typecast_timestamp(dt)
|
dt = backend_utils.typecast_timestamp(dt)
|
||||||
except (ValueError, TypeError):
|
except (TypeError, ValueError):
|
||||||
|
return None
|
||||||
|
if tzname is not None:
|
||||||
|
dt = timezone.localtime(dt, pytz.timezone(tzname))
|
||||||
|
return dt
|
||||||
|
|
||||||
|
|
||||||
|
def _sqlite_date_extract(lookup_type, dt):
|
||||||
|
dt = _sqlite_datetime_parse(dt)
|
||||||
|
if dt is None:
|
||||||
return None
|
return None
|
||||||
if lookup_type == 'week_day':
|
if lookup_type == 'week_day':
|
||||||
return (dt.isoweekday() % 7) + 1
|
return (dt.isoweekday() % 7) + 1
|
||||||
|
@ -345,9 +354,8 @@ def _sqlite_date_extract(lookup_type, dt):
|
||||||
|
|
||||||
|
|
||||||
def _sqlite_date_trunc(lookup_type, dt):
|
def _sqlite_date_trunc(lookup_type, dt):
|
||||||
try:
|
dt = _sqlite_datetime_parse(dt)
|
||||||
dt = backend_utils.typecast_timestamp(dt)
|
if dt is None:
|
||||||
except (ValueError, TypeError):
|
|
||||||
return None
|
return None
|
||||||
if lookup_type == 'year':
|
if lookup_type == 'year':
|
||||||
return "%i-01-01" % dt.year
|
return "%i-01-01" % dt.year
|
||||||
|
@ -376,18 +384,6 @@ def _sqlite_time_trunc(lookup_type, dt):
|
||||||
return "%02i:%02i:%02i" % (dt.hour, dt.minute, dt.second)
|
return "%02i:%02i:%02i" % (dt.hour, dt.minute, dt.second)
|
||||||
|
|
||||||
|
|
||||||
def _sqlite_datetime_parse(dt, tzname):
|
|
||||||
if dt is None:
|
|
||||||
return None
|
|
||||||
try:
|
|
||||||
dt = backend_utils.typecast_timestamp(dt)
|
|
||||||
except (ValueError, TypeError):
|
|
||||||
return None
|
|
||||||
if tzname is not None:
|
|
||||||
dt = timezone.localtime(dt, pytz.timezone(tzname))
|
|
||||||
return dt
|
|
||||||
|
|
||||||
|
|
||||||
def _sqlite_datetime_cast_date(dt, tzname):
|
def _sqlite_datetime_cast_date(dt, tzname):
|
||||||
dt = _sqlite_datetime_parse(dt, tzname)
|
dt = _sqlite_datetime_parse(dt, tzname)
|
||||||
if dt is None:
|
if dt is None:
|
||||||
|
|
Loading…
Reference in New Issue