From 08b110ffccf62fdd2f4474a7199ef31bfd7880a0 Mon Sep 17 00:00:00 2001 From: sujanadh Date: Mon, 25 Dec 2023 15:58:05 +0545 Subject: [PATCH] fix: more robust method to support different date format --- src/backend/app/projects/project_schemas.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/app/projects/project_schemas.py b/src/backend/app/projects/project_schemas.py index 3224a6247c..e951ca377d 100644 --- a/src/backend/app/projects/project_schemas.py +++ b/src/backend/app/projects/project_schemas.py @@ -18,6 +18,7 @@ import uuid from datetime import datetime +from dateutil import parser from typing import List, Optional from geojson_pydantic import Feature as GeojsonFeature @@ -166,8 +167,10 @@ def get_last_active(cls, value, values): if value is None: return None + last_active = parser.parse(value).replace(tzinfo=None) current_date = datetime.now() - time_difference = current_date - datetime.strptime(value, "%Y-%m-%d %H:%M:%S.%f") + + time_difference = current_date - last_active days_difference = time_difference.days @@ -178,5 +181,4 @@ def get_last_active(cls, value, values): elif days_difference < 7: return f'{days_difference} day{"s" if days_difference > 1 else ""} ago' else: - value = datetime.strptime(value, '%Y-%m-%d %H:%M:%S.%f') - return datetime.strftime(value, "%d %b %Y") \ No newline at end of file + return last_active.strftime("%d %b %Y") \ No newline at end of file