Skip to content

Commit 161b566

Browse files
committed
Fix dates in stats command
1 parent 58f3804 commit 161b566

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/commands/stats.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import type { Command } from '../types';
55
import { getDateForWeekNumber, getWeekNumber } from '../utils';
66

77
const formatDate = (d: Date) =>
8-
String(d.getUTCFullYear()) +
8+
String(d.getFullYear()) +
99
'-' +
10-
String(d.getUTCMonth() + 1).padStart(2, '0') +
10+
String(d.getMonth() + 1).padStart(2, '0') +
1111
'-' +
12-
String(d.getUTCDate()).padStart(2, '0');
12+
String(d.getDate()).padStart(2, '0');
1313

1414
const stats: Command = {
1515
name: 'stats',
@@ -19,16 +19,22 @@ const stats: Command = {
1919
async execute(msg) {
2020
const db = await initDb();
2121

22-
const { totalStats, statsThisWeek, year1, year2, week1, week2 } = await getStatsChangeThisWeek(
23-
db,
24-
);
22+
const { totalStats, statsThisWeek, year1, week1 } = await getStatsChangeThisWeek(db);
23+
24+
// Monday
25+
const d1 = getDateForWeekNumber(year1, week1);
26+
d1.setUTCDate(d1.getUTCDate() - (d1.getUTCDay() || 7));
2527

26-
const d1 = formatDate(getDateForWeekNumber(year2, week2));
27-
const d2 = formatDate(getDateForWeekNumber(year1, week1));
28+
// Sunday
29+
const d2 = new Date(d1);
30+
d2.setUTCDate(d2.getUTCDate() + 6);
2831

2932
return msg.channel.send(
3033
[
31-
format(`Najbardziej aktywne osoby w tym tygodniu (${d1}${d2}):`, statsThisWeek),
34+
format(
35+
`Najbardziej aktywne osoby w tym tygodniu (${formatDate(d1)}${formatDate(d2)}):`,
36+
statsThisWeek,
37+
),
3238
'\n',
3339
format('Najbardziej aktywne osoby od początku istnienia serwera:', totalStats),
3440
].join('\n'),

0 commit comments

Comments
 (0)