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/base/operations.py | |
| parent | 8d018231ac64c044c9740b79c0acf6d0abd7c513 (diff) | |
Fixed #31640 -- Made Trunc() truncate datetimes to Date/TimeField in a specific timezone.
Diffstat (limited to 'django/db/backends/base/operations.py')
| -rw-r--r-- | django/db/backends/base/operations.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py index 2319cb6306..0fcc607bcf 100644 --- a/django/db/backends/base/operations.py +++ b/django/db/backends/base/operations.py @@ -99,11 +99,14 @@ class BaseDatabaseOperations: """ raise NotImplementedError('subclasses of BaseDatabaseOperations may require a date_extract_sql() method') - def date_trunc_sql(self, lookup_type, field_name): + def date_trunc_sql(self, lookup_type, field_name, tzname=None): """ Given a lookup_type of 'year', 'month', or 'day', return the SQL that - truncates the given date field field_name to a date object with only - the given specificity. + truncates the given date or datetime field field_name to a date object + with only the given specificity. + + If `tzname` is provided, the given value is truncated in a specific + timezone. """ raise NotImplementedError('subclasses of BaseDatabaseOperations may require a date_trunc_sql() method.') @@ -138,11 +141,14 @@ class BaseDatabaseOperations: """ raise NotImplementedError('subclasses of BaseDatabaseOperations may require a datetime_trunc_sql() method') - def time_trunc_sql(self, lookup_type, field_name): + def time_trunc_sql(self, lookup_type, field_name, tzname=None): """ Given a lookup_type of 'hour', 'minute' or 'second', return the SQL - that truncates the given time field field_name to a time object with - only the given specificity. + that truncates the given time or datetime field field_name to a time + object with only the given specificity. + + If `tzname` is provided, the given value is truncated in a specific + timezone. """ raise NotImplementedError('subclasses of BaseDatabaseOperations may require a time_trunc_sql() method') |
