﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31640	Trunc() function take tzinfo param into account only when DateTimeField() are used as output_field	Serhii Romanov	David Wobrock	"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?**"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed	trunc timezone tz	David Rasch David Wobrock	Ready for checkin	1	0	0	0	0	0
