Skip to content

Commit

Permalink
fix(time): repeated segment starts and ends on the same day
Browse files Browse the repository at this point in the history
  • Loading branch information
ZTL-UwU committed Dec 10, 2023
1 parent b93547d commit a5e3ea5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions server/trpc/controllers/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export class TimeController {
return true; // This is to prevent a total shutdown when getList breaks
const list = listRes.res;

let fits = 0;
for (const time of list) {
if (!time.isActive)
continue;
Expand All @@ -93,21 +92,23 @@ export class TimeController {
m: d.getMinutes(),
s: d.getSeconds(),
});
const date2num = (d: ReturnType<typeof dhms>) => d.h * 10000 + d.m * 100 + d.s;
const date2num = (d: ReturnType<typeof dhms>) => d.d * 1000000 + d.h * 10000 + d.m * 100 + d.s;

const start = dhms(time.startAt);
const end = dhms(time.endAt);
const current = dhms(t);

if ((start.d < end.d && (current.d < start.d || end.d < current.d)) || (start.d > end.d && current.d < start.d))
continue;
if (start.d === end.d && (date2num(current) < date2num(start) || date2num(current) > date2num(end)))
continue;
if (current.d === start.d && date2num(current) < date2num(start))
continue;
if (current.d === end.d && date2num(current) > date2num(end))
continue;
}
fits++;
return true;
}
return fits > 0;
return false;
}
}

0 comments on commit a5e3ea5

Please sign in to comment.