#31640: Trunc() function take tzinfo param into account only when 
DateTimeField()
are used as output_field
-------------------------------------+-------------------------------------
               Reporter:  Serhiy     |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  master
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:  trunc timezone tz
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 I'm trying to use TruncDay() function like this
 {{{
 TruncDay('created_at', output_field=DateField(), tzinfo=tz_kyiv)
 }}}
 but for PostgresSQL the code are generated as
 {{{
 (DATE_TRUNC('day', "storage_transaction"."created_at"))
 }}}
 So timezone convertation like
 {{{
 AT TIME ZONE 'Europe/Kiev'
 }}}
 was totally missed from sql.

 After the investigation of code I've found out that Timezone converting
 are applied only when output_field=DateTimeField

 {{{
     def as_sql(self, compiler, connection):
         inner_sql, inner_params = compiler.compile(self.lhs)
         if isinstance(self.output_field, DateTimeField):
             tzname = self.get_tzname()
             sql = connection.ops.datetime_trunc_sql(self.kind, inner_sql,
 tzname)
         elif isinstance(self.output_field, DateField):
             sql = connection.ops.date_trunc_sql(self.kind, inner_sql)
         elif isinstance(self.output_field, TimeField):
             sql = connection.ops.time_trunc_sql(self.kind, inner_sql)
         else:
             raise ValueError('Trunc only valid on DateField, TimeField, or
 DateTimeField.')
         return sql, inner_params
 }}}

 **Why is that? Is there any reason for it OR is it only such feature that
 isn't still implemented?**

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31640>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/056.8420579fb33863eae7e0e728f853eb26%40djangoproject.com.

Reply via email to