diff --git a/bots/discord/package.json b/bots/discord/package.json index e3e75dd..a6ccb27 100644 --- a/bots/discord/package.json +++ b/bots/discord/package.json @@ -35,7 +35,8 @@ "chalk": "^5.3.0", "decancer": "^3.2.3", "discord.js": "^14.15.3", - "drizzle-orm": "^0.31.4" + "drizzle-orm": "^0.31.4", + "parse-duration": "^1.1.0" }, "devDependencies": { "@libsql/client": "^0.7.0", diff --git a/bots/discord/src/utils/duration.ts b/bots/discord/src/utils/duration.ts index 64e672c..4f4e129 100644 --- a/bots/discord/src/utils/duration.ts +++ b/bots/discord/src/utils/duration.ts @@ -1,18 +1,6 @@ -export const parseDuration = (duration: string) => { - if (!duration.length) return Number.NaN - const matches = duration.match(/(?:(\d+y)?(\d+M)?(\d+w)?(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)/)! +import parse from 'parse-duration' - const [, years, months, weeks, days, hours, minutes, seconds] = matches.map(Number) - return ( - (years || 0) * 290304e5 + - (months || 0) * 24192e5 + - (weeks || 0) * 6048e5 + - (days || 0) * 864e5 + - (hours || 0) * 36e5 + - (minutes || 0) * 6e4 + - (seconds || 0) * 1e3 - ) -} +export const parseDuration = (duration: string) => parse(duration, 'ms') ?? Number.NaN export const durationToString = (duration: number) => { if (duration === 0) return '0s' diff --git a/bun.lockb b/bun.lockb index 991adf7..c8ffb65 100755 Binary files a/bun.lockb and b/bun.lockb differ