Skip to content

Commit 6e76046

Browse files
committedJan 23, 2024
Check for empty value in localtime filter
1 parent 3985e89 commit 6e76046

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed
 

‎bolt/templates/jinja/filters.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@
55
from bolt.utils.timesince import timesince, timeuntil
66
from bolt.utils.timezone import localtime
77

8+
9+
def localtime_filter(value, timezone=None):
10+
"""Converts a datetime to local time in a template."""
11+
if not value:
12+
# Without this, we get the current localtime
13+
# which doesn't make sense as a filter
14+
return ""
15+
return localtime(value, timezone)
16+
17+
818
default_filters = {
919
# The standard Python ones
1020
"strftime": datetime.datetime.strftime,
1121
"strptime": datetime.datetime.strptime,
1222
# To convert to user time zone
13-
"localtime": localtime,
23+
"localtime": localtime_filter,
1424
"timeuntil": timeuntil,
1525
"timesince": timesince,
1626
"json_script": json_script,

0 commit comments

Comments
 (0)
Please sign in to comment.