Igor Popov

08/18/2023, 1:00 PM
Hello everyone, I have a challenge with my Jinja2 templates. I’m trying to convert a UTC timestamp to a different timezone (UTC+6) directly within the template, but I’ve encountered some constraints. Here’s the context: I’m using this block in my template for Prefect Cloud Automation:
Copy code
Last polled: {{ work_queue.last_polled }}
value is in UTC. However, I learned that Jinja2 does not provide direct datetime arithmetic or timezone operations as a built-in. Here’s a summary of what I gathered: 1. Jinja2 doesn’t have built-in filters to manage datetime arithmetic or timezone operations. 2. Normally, such operations are handled in the application logic before the data is passed to the template. 3. If working with string representations, doing string manipulations for timezones would be hacky and error-prone. Given these constraints, I’m looking for advice on the best way to approach this problem. Has anyone found a workaround to handle timezones within Jinja2 templates, especially without adding custom Python code? Any advice or suggestions would be greatly appreciated! Thanks in advance!