Skip to content

Commit

Permalink
fix(time): better timedelta format for seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
ZRunner committed Nov 19, 2023
1 parent 2f32bef commit 8dd76a4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libs/formatutils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time
from datetime import datetime, timedelta
from typing import Union, Literal
from typing import Literal, Union

from babel import dates, numbers
from dateutil.relativedelta import relativedelta
Expand Down Expand Up @@ -83,6 +83,8 @@ async def time_delta(date1: Union[datetime, int], date2: datetime = None,
if seconds and delta.seconds > 0:
# add formatted seconds
result += dates.format_timedelta(timedelta(seconds=delta.seconds), granularity="second", **kwargs) + " "
elif not seconds and len(result.strip()) == 0 and delta.seconds > 0:
result += "<" + dates.format_timedelta(timedelta(minutes=1), granularity="minute", **kwargs)

return result.strip()

Expand Down

0 comments on commit 8dd76a4

Please sign in to comment.