Skip to content

Commit

Permalink
fix: more robust method to support different date format
Browse files Browse the repository at this point in the history
  • Loading branch information
sujanadh committed Dec 25, 2023
1 parent dad8d38 commit 08b110f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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")
return last_active.strftime("%d %b %Y")

0 comments on commit 08b110f

Please sign in to comment.