fix #182
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 19s

This commit is contained in:
Mylloon 2024-09-27 16:33:15 +02:00
parent 78a84faca4
commit 1bc77efb2a
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -53,18 +53,21 @@ export const strToSeconds = (time: string) => {
RegExpFlags.Global | RegExpFlags.Insensitive, RegExpFlags.Global | RegExpFlags.Insensitive,
); );
const data = Object.assign({}, regex.exec(time)?.groups); const data = Array.from(time.matchAll(regex));
if (data.length === 0) {
if (Object.keys(data).length === 0) {
// Regex returned an invalid time // Regex returned an invalid time
return -1; return -1;
} }
let res = 0; let res = 0;
Object.entries(data).forEach(([key, value]) => { data.forEach((match) => {
if (value) { console.log(match.groups);
res += +value * TimeSecond[key as keyof typeof TimeSecond];
} Object.entries(match.groups!).forEach(([key, value]) => {
if (value) {
res += +value * TimeSecond[key as keyof typeof TimeSecond];
}
});
}); });
return res; return res;