diff options
| author | David-Wobrock <david.wobrock@gmail.com> | 2020-10-04 19:28:21 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-10-14 20:06:26 +0200 |
| commit | ee005328c8eec5c013c6bf9d6fbb2ae9d540df14 (patch) | |
| tree | 5d9641ee00639c05b815cbc26061744e039552d5 /django/db/backends/sqlite3/operations.py | |
| parent | 8d018231ac64c044c9740b79c0acf6d0abd7c513 (diff) | |
Fixed #31640 -- Made Trunc() truncate datetimes to Date/TimeField in a specific timezone.
Diffstat (limited to 'django/db/backends/sqlite3/operations.py')
| -rw-r--r-- | django/db/backends/sqlite3/operations.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/django/db/backends/sqlite3/operations.py b/django/db/backends/sqlite3/operations.py index 1f77b3109f..71ef000c93 100644 --- a/django/db/backends/sqlite3/operations.py +++ b/django/db/backends/sqlite3/operations.py @@ -77,14 +77,22 @@ class DatabaseOperations(BaseDatabaseOperations): """Do nothing since formatting is handled in the custom function.""" return sql - def date_trunc_sql(self, lookup_type, field_name): - return "django_date_trunc('%s', %s)" % (lookup_type.lower(), field_name) + def date_trunc_sql(self, lookup_type, field_name, tzname=None): + return "django_date_trunc('%s', %s, %s, %s)" % ( + lookup_type.lower(), + field_name, + *self._convert_tznames_to_sql(tzname), + ) - def time_trunc_sql(self, lookup_type, field_name): - return "django_time_trunc('%s', %s)" % (lookup_type.lower(), field_name) + def time_trunc_sql(self, lookup_type, field_name, tzname=None): + return "django_time_trunc('%s', %s, %s, %s)" % ( + lookup_type.lower(), + field_name, + *self._convert_tznames_to_sql(tzname), + ) def _convert_tznames_to_sql(self, tzname): - if settings.USE_TZ: + if tzname and settings.USE_TZ: return "'%s'" % tzname, "'%s'" % self.connection.timezone_name return 'NULL', 'NULL' |
