Skip to content

Commit

Permalink
Fix elapsed time not working because of difference between local and …
Browse files Browse the repository at this point in the history
…gmt datetime
  • Loading branch information
ValentinBuira committed Oct 30, 2024
1 parent a5c39ef commit a02c234
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Mergin/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import shutil
from datetime import datetime, timezone
from datetime import datetime, timezone, tzinfo
from enum import Enum
from urllib.error import URLError, HTTPError
import configparser
Expand Down Expand Up @@ -1518,12 +1518,13 @@ def check_mergin_subdirs(directory):
return False


def contextual_date(date_string, start_date=None):
def contextual_date(date_string):
"""Converts datetime string returned by the server into contextual duration string, e.g.
'N hours/days/month ago'
"""
dt = datetime.strptime(date_string, "%Y-%m-%dT%H:%M:%SZ")
now = datetime.now() if start_date is None else datetime.strptime(start_date, "%Y-%m-%dT%H:%M:%SZ")
dt = dt.replace(tzinfo=timezone.utc)
now = datetime.now(timezone.utc)
delta = now - dt
if delta.days > 365:
years = now.year - dt.year - ((now.month, now.day) < (dt.month, dt.day))
Expand Down

0 comments on commit a02c234

Please sign in to comment.