0

My .odt template file contains a link to datetime field as a template directive. While char directives works perfectly, this one has a problem: it shows time "as is" in postgresql (UTC timezone) instead of UTC+7.

I suppose I could somehow add 7 hours right in the directive field of my .odt template file, but I don't know how. I've tried something like

(o.visitdt) + relativedelta(hours=7)

where visitdt is my datetime field, but, of course, it gives an error. So, what's the right syntax then? Or am I supposed to do something else to make that field display correctly?

Thanks in advance.

Scraggesh
  • 131
  • 1
  • 12

1 Answers1

0

I spend a day, trying to pick up a key to that question, and, as I found, it can be done via template directive. As it was said on aeroo reports wiki, the only time related functions (which it able to understand) are

Time related functions

dec_to_time - converts time to hh:min representation;

time - time access and conversions;

There is timezone setting command in the time module, but I failed to make it work because I cannot set timezone at first, before accepting changes with tzset(), directive refused to understand it. Maybe it was just me, but I've decided to find another way.

Here it is. Probably it's not the best decision, but it works, so I'll use this scheme until I find something better.

I split my datetime field into three sections:

time.strftime("%d.%m.%Y", time.strptime(str(o.visitdt), "%Y-%m-%d %H:%M:%S"))

is my date, all right here,

(time.strptime(str(o.visitdt), "%Y-%m-%d %H:%M:%S"))[3]+07

and that's hours' part, I pulled it from the time tuple and increased by 7 (my timezone),

time.strftime("%M", time.strptime(str(o.visitdt), "%Y-%m-%d %H:%M:%S"))

last part — minutes (unaffected).

In result, we have exact date and time we wanted (19.10.2017 11:00 for example).

P.S. Of course, it won't work if we'll set hours <7, but since it's out of my array of available time interval (8-17), it'll work as a temporary decision.

Community
  • 1
  • 1
Scraggesh
  • 131
  • 1
  • 12