From d4dcbce4dfc003d00690514a2db48240b8add11d Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Tue, 25 Jul 2023 11:49:22 +0530 Subject: [PATCH] handle exception in template date parsing Signed-off-by: Aakash Singh --- care/facility/templatetags/filters.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/care/facility/templatetags/filters.py b/care/facility/templatetags/filters.py index e3e4910300..9a8bc576fa 100644 --- a/care/facility/templatetags/filters.py +++ b/care/facility/templatetags/filters.py @@ -27,4 +27,7 @@ def field_name_to_label(value): @register.filter(expects_localtime=True) def parse_datetime(value): - return datetime.strptime(value, "%Y-%m-%dT%H:%M") + try: + return datetime.strptime(value, "%Y-%m-%dT%H:%M") + except ValueError: + return None