Open
Description
I tried to use the following expression:
{% now 'local' - 'days=1', '%d %b %Y %H:%M:%S' %}
which leads to the following error: ValueError: Unknown attribute: 'days'
I am working with:
Package Version
--------------- -------
arrow 1.2.1
Jinja2 3.0.3
jinja2-time 0.2.0
In more detail this is the script:
import jinja2
from jinja2 import Environment, BaseLoader
env = Environment(loader=BaseLoader(), extensions=['jinja2_time.TimeExtension'])
myString = "{% now 'local' - 'days=1', '%d %b %Y %H:%M:%S' %}"
rtemplate = env.from_string(myString)
data = rtemplate.render()
print(data)
and this is the output:
Traceback (most recent call last):
File "P:\Programming\Python\temp\test_jinja2_time.py", line 9, in <module>
data = rtemplate.render()
File "P:\Programming\Python\temp\sandbox\lib\site-packages\jinja2\environment.py", line 1291, in render
self.environment.handle_exception()
File "P:\Programming\Python\temp\sandbox\lib\site-packages\jinja2\environment.py", line 925, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "P:\Programming\Python\temp\sandbox\lib\site-packages\jinja2_time\jinja2_time.py", line 26, in _datetime
d = d.replace(**replace_params)
File "P:\Programming\Python\temp\sandbox\lib\site-packages\arrow\arrow.py", line 974, in replace
raise ValueError(f"Unknown attribute: {key!r}.")
ValueError: Unknown attribute: 'days'.
Looking at the source code, it looks like the d = d.replace(**replace_params)
should be switched to d = d.shift(**replace_params)
to achieve relative time offset. I did quickly test this against this specific expression and it worked as expected (for this expression).
Metadata
Metadata
Assignees
Labels
No labels