From b14b8a88e076bd01e6ff6104d50e0a5340e446fb Mon Sep 17 00:00:00 2001 From: PythonCoderAS <13932583+PythonCoderAS@users.noreply.github.com> Date: Wed, 5 Jan 2022 21:18:53 -0500 Subject: [PATCH] Sort times based on total minutes. Fix #422 --- src/commands/stats.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/commands/stats.ts b/src/commands/stats.ts index 438a88a9..2bf3e6cb 100644 --- a/src/commands/stats.ts +++ b/src/commands/stats.ts @@ -40,7 +40,7 @@ export default class Stats extends Command { members += value.memberCount; }); // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore: Sequelize provides incorrect types to us + // @ts-ignore: Sequelize provides incorrect types to us. const timeCounts: { hour: number; minute: number; count: number }[] = await AutoUser.count({ group: ["hour", "minute"], @@ -75,6 +75,11 @@ export default class Stats extends Command { }) .setDescription( timeCounts + .sort((a, b) => { + const aTotalMinutes = a.hour * 60 + a.minute; + const bTotalMinutes = b.hour * 60 + b.minute; + return aTotalMinutes - bTotalMinutes; + }) .map((value) => { const hour12 = value.hour % 12 || 12; const isPM = value.hour >= 12;