Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Commit 4ce3870

Browse files
committed
Improved code quality in the time converter
1 parent 0735ca7 commit 4ce3870

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

PyDrocsid/converter.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
from datetime import timedelta
33

4+
from dateutil.relativedelta import relativedelta
45
from discord import Guild, HTTPException, Member, NotFound, PartialEmoji, User
56
from discord.ext.commands import Bot
67
from discord.ext.commands.context import Context
@@ -78,10 +79,8 @@ async def convert(self, ctx: Context[Bot], argument: str) -> int | None:
7879
0 if (value := match.group(i)) is None else int(value[:-1]) for i in range(1, 7)
7980
]
8081

81-
years += days * 365
82-
days += months * 30
83-
days += weeks * 7
84-
td = timedelta(days=days, hours=hours, minutes=minutes)
82+
rd = relativedelta(years=years, months=months, weeks=weeks, days=days)
83+
td = timedelta(days=rd.days, hours=hours, minutes=minutes)
8584
duration = int(td.total_seconds() / 60)
8685

8786
if duration <= 0:

0 commit comments

Comments
 (0)