Skip to content

Commit

Permalink
Improve robustness of built-in tags to better cope with invalid blood…
Browse files Browse the repository at this point in the history
…hound data
  • Loading branch information
neonbunny committed Nov 8, 2024
1 parent 23eda35 commit 5a6d16f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions event_tracker/templatetags/custom_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ def linebreaksword(value):

@register.filter
def epoch_to_ts(epoch_time):
return datetime.datetime.fromtimestamp(epoch_time, tz=datetime.timezone.utc)
try:
return datetime.datetime.fromtimestamp(epoch_time, tz=datetime.timezone.utc)
except:
return f"Could not convert: {epoch_time}"


@register.filter
Expand All @@ -245,7 +248,10 @@ def render_ts_to_ts_utc(value, until):

@register.filter
def render_ts_local(value):
return f"{date_format(value, 'SHORT_DATE_FORMAT')} {localtime(value).strftime('%H:%M')}"
if isinstance(value, datetime.datetime):
return f"{date_format(value, 'SHORT_DATE_FORMAT')} {localtime(value).strftime('%H:%M')}"
else:
return f"Not a datetime: {value}"


@register.filter
Expand Down

0 comments on commit 5a6d16f

Please sign in to comment.