fix bug d'affichage avec les heures du reminder

This commit is contained in:
Mylloon 2021-08-02 11:11:02 +02:00
parent c09c791f12
commit e801be8362

View file

@ -1,6 +1,6 @@
from pytz import timezone
from datetime import datetime, timedelta
from re import findall
from re import findall, sub
from utils.core import load
myTimezone = load(["TIMEZONE"])["TIMEZONE"]
@ -56,20 +56,21 @@ def timestampScreen(timestamp):
def timedeltaToString(time):
"""Différence entre une heure en seconde et maintenant"""
age = str(timedelta(seconds = time)).replace('day', 'jour').replace(', ', ':').split(':')
if len(age) == 4:
a = [1, 1, 1, 1] # a pour affichage
age = sub(r' days?, ', ':', str(timedelta(seconds = time))).split(':')
affichage = [1, 1, 1, 1] # len(age) == 4
if len(age) == 3:
a = [0, 1, 1, 1]
affichage = [0, 1, 1, 1]
age.insert(0, None)
for i in range(1, 4):
for i in range(1, len(affichage)):
if int(age[i]) == 0:
a[i] = 0
age[0] = age[0] if a[0] == 1 else ''
age[1] = f", {age[1]}h " if a[1] == 1 else ''
age[2] = f"{age[2]}m " if a[2] == 1 else ''
age[3] = f"{age[3]}s" if a[3] == 1 else ''
return ''.join(age).strip(' ')
affichage[i] = 0
age[0] = f"{age[0]} jour{'s' if int(age[0]) > 1 else ''}" if affichage[0] == 1 else ''
age[1] = f"{age[1]}h" if affichage[1] == 1 else ''
age[2] = f"{age[2]}m" if affichage[2] == 1 else ''
age[3] = f"{age[3]}s" if affichage[3] == 1 else ''
while "" in age:
age.remove("")
return ', '.join(age).strip(' ')
def getAge(date):
"""Décompose la différence entre une date et maintenant avec les bons timezone"""