Skip to content

Commit

Permalink
Merge pull request #1058 from hotosm/fix-date-issue
Browse files Browse the repository at this point in the history
fix: Issue of Custom date format for over 7days
  • Loading branch information
nrjadkry authored Dec 25, 2023
2 parents db32567 + 08b110f commit 0badc07
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 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,4 +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:
return value.strftime("%d %b %Y")
return last_active.strftime("%d %b %Y")

0 comments on commit 0badc07

Please sign in to comment.