feat: more readable time delta #193

Merged
Anri merged 6 commits from date into dev 2024-10-08 20:53:29 +02:00
Owner

Close #189

Close #189
Anri added 2 commits 2024-10-01 00:08:11 +02:00
better time delta when creating a reminder
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 25s
208dbf0813
Author
Owner

Currently the issue is that a reminder set in "2h30" returns "in 3h"
The API is too approximative

Currently the issue is that a reminder set in "2h30" returns "in 3h" The API is too approximative
Author
Owner

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(' ')

Reference to how KassouBot dealed with the issue: https://git.mylloon.fr/ConfrerieDuKassoulait/KassouBot/src/commit/54ab6d4dd5c252ee77be612abe7fb73119e48f5c/src/utils/time.py#L71-L101
Anri changed target branch from main to dev 2024-10-08 16:45:08 +02:00
Anri added a new dependency 2024-10-08 16:58:40 +02:00
Anri added 1 commit 2024-10-08 20:11:31 +02:00
more precise calculation
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 18s
5bf6b48d21
Anri added 1 commit 2024-10-08 20:11:44 +02:00
use blank character
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 18s
56762aaa05
Anri added 1 commit 2024-10-08 20:38:14 +02:00
simplify code
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 16s
095aa7f68c
Anri added 1 commit 2024-10-08 20:52:24 +02:00
add tests
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 16s
bfc3b008cc
Anri merged commit 85933e3ca2 into dev 2024-10-08 20:53:29 +02:00
Anri deleted branch date 2024-10-08 20:53:29 +02:00
Anri referenced this pull request from a commit 2024-10-08 20:53:31 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
#194 chore: merge branch dev to main}
ConfrerieDuKassoulait/Botanique
Reference: ConfrerieDuKassoulait/Botanique#193
No description provided.