|
1 | | -from datetime import datetime |
2 | 1 | from functools import partialmethod |
3 | 2 |
|
4 | | -from django.conf import settings |
5 | 3 | from django.db import NotSupportedError |
6 | | -from django.db.models import DateField, DateTimeField, TimeField |
7 | 4 | from django.db.models.expressions import Func |
8 | 5 | from django.db.models.functions import JSONArray |
9 | 6 | from django.db.models.functions.comparison import Cast, Coalesce, Greatest, Least, NullIf |
@@ -209,36 +206,6 @@ def trunc(self, compiler, connection): |
209 | 206 | return {"$dateTrunc": lhs_mql} |
210 | 207 |
|
211 | 208 |
|
212 | | -_trunc_convert_value = TruncBase.convert_value |
213 | | - |
214 | | - |
215 | | -def trunc_convert_value(self, value, expression, connection): |
216 | | - if connection.vendor == "mongodb": |
217 | | - # A custom TruncBase.convert_value() for MongoDB. |
218 | | - if value is None: |
219 | | - return None |
220 | | - convert_to_tz = settings.USE_TZ and self.get_tzname() != "UTC" |
221 | | - if isinstance(self.output_field, DateTimeField): |
222 | | - if convert_to_tz: |
223 | | - # Unlike other databases, MongoDB returns the value in UTC, |
224 | | - # so rather than setting the time zone equal to self.tzinfo, |
225 | | - # the value must be converted to tzinfo. |
226 | | - value = value.astimezone(self.tzinfo) |
227 | | - elif isinstance(value, datetime): |
228 | | - if isinstance(self.output_field, DateField): |
229 | | - if convert_to_tz: |
230 | | - value = value.astimezone(self.tzinfo) |
231 | | - # Truncate for Trunc(..., output_field=DateField) |
232 | | - value = value.date() |
233 | | - elif isinstance(self.output_field, TimeField): |
234 | | - if convert_to_tz: |
235 | | - value = value.astimezone(self.tzinfo) |
236 | | - # Truncate for Trunc(..., output_field=TimeField) |
237 | | - value = value.time() |
238 | | - return value |
239 | | - return _trunc_convert_value(self, value, expression, connection) |
240 | | - |
241 | | - |
242 | 209 | def trunc_date(self, compiler, connection): |
243 | 210 | # Cast to date rather than truncate to date. |
244 | 211 | lhs_mql = process_lhs(self, compiler, connection, as_expr=True) |
@@ -311,7 +278,6 @@ def register_functions(): |
311 | 278 | Substr.as_mql_expr = substr |
312 | 279 | Trim.as_mql_expr = trim("trim") |
313 | 280 | TruncBase.as_mql_expr = trunc |
314 | | - TruncBase.convert_value = trunc_convert_value |
315 | 281 | TruncDate.as_mql_expr = trunc_date |
316 | 282 | TruncTime.as_mql_expr = trunc_time |
317 | 283 | Upper.as_mql_expr = preserve_null("toUpper") |
|
0 commit comments