Unable to display timezone-aware date on reports

19 views
Skip to first unread message

Khurram Shahzad

unread,
Mar 12, 2018, 4:40:05 AM3/12/18
to tryton
Hi all,

We are displaying 'Printed On' date/time on our ODT reports using:
<FORMAT_DATE(DATETIME.DATE.TODY(),USER.LANGUAGE)>
<DATETIME.DATE.TODAY().STRFTIME('%H:%M:%S')>

But it is displaying date/time in UTC; i.e. it is not taking into account our timezone.

On some reports, this issue is resolved by calling a method in the Report class which just adjusts the date as under:

datetime.astimezone(dt.replace(tzinfo=pytz.utc), timezone)

where 'dt' is the date to be adjusted and 'timezone' is the required timezone.

My question is, is there any way that we can do this adjustment in the report and eliminate the need of writing/calling method just to get the date adjusted?

By the way, I tried to use the same line to adjust the date but it gives error on 'pytz'. How can I import it in my reports? And, which python packages are by-default available in reports?

Cédric Krier

unread,
Mar 12, 2018, 5:15:05 AM3/12/18
to tryton
On 2018-03-11 23:48, Khurram Shahzad wrote:
> My question is, is there any way that we can do this adjustment in the
> report and eliminate the need of writing/calling method just to get
> the date adjusted?

There will always be the need to call a method with the proper timezone
to use.
There is https://bugs.tryton.org/issue7202 which aims to simplify the work.

> By the way, I tried to use the same line to adjust the date but it gives error on 'pytz'.

Normal timezone applies only on datetime, there is no timezone for date
(as the name implies).

> How can I import it in my reports? And, which python packages are by-default available in reports?

The default context in Report has only datetime module everything else
must be adding by override Report.get_context.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Khurram Shahzad

unread,
Mar 13, 2018, 4:40:17 AM3/13/18
to tryton
Thank you so much for your kind response.
Reply all
Reply to author
Forward
0 new messages