feat: more readable time delta #193
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Blocks
#194 chore: merge branch
dev
to main
}
ConfrerieDuKassoulait/Botanique
Reference: ConfrerieDuKassoulait/Botanique#193
Loading…
Reference in a new issue
No description provided.
Delete branch "date"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Close #189
Currently the issue is that a reminder set in "2h30" returns "in 3h"
The API is too approximative
Reference to how KassouBot dealed with the issue:
def timedeltaToString(time):
"""Différence entre une heure en seconde et maintenant"""
age = sub(r' days?, ', ':', str(timedelta(seconds = time))).split(':')
affichage = [1, 1, 1, 1]
if len(age) == 3:
affichage = [0, 1, 1, 1]
age.insert(0, None)
for i in range(1, len(affichage)):
if int(age[i]) == 0:
affichage[i] = 0
if affichage[0] == 1:
day = int(age[0]) # récupération du nombre de jour
year = day // 365 # ajout du nombre d'année
day -= year * 365 # suppression des années dans le nombre de jour
week = day // 7 # ajout du nombres de semaines
day -= week * 7 # suppression des semaines dans le nombre du jour
year = f"{year} an{'s' if year > 1 else ''}" if year > 0 else ""
week = f"{week} semaine{'s' if week > 1 else ''}" if week > 0 else ""
day = f"{day} jour{'s' if day > 1 else ''}" if day > 0 else ""
_ageTemp = [year, week, day]
while "" in _ageTemp:
_ageTemp.remove("")
age[0] = ', '.join(_ageTemp).strip(' ')
else:
age[0] = ""
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(' ')
dev
tomain