Skip to content

Commit 5807ab0

Browse files
Merge pull request #7 from kcoderhtml/Add-timestamp-to-leaderboard
Add timestamp to leaderboard
2 parents aaf4374 + 5ef7927 commit 5807ab0

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

utils/slack.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,19 @@ function generateLeaderboardTable(users: user[]): string {
3535
);
3636

3737
const userCell = ` ${user.user}${" ".repeat(maxUsernameLength - user.user.length)} `;
38-
const cells = uniqueTimestamps.map((timestamp, index) =>
39-
postsByDate.has(timestamp)
40-
? " ✓".padEnd(dateLengths[index] + 2)
41-
: " ".repeat(dateLengths[index] + 2),
42-
);
38+
const cells = uniqueTimestamps.map((timestamp, index) => {
39+
const date = postsByDate.has(timestamp)
40+
? user.posts.find(
41+
(p) => p.timestamp.toISOString().split("T")[0] === timestamp,
42+
)
43+
: null;
44+
45+
return date
46+
? ` ✓ ${date.timestamp.getUTCHours()}:${user.posts[0].timestamp.getUTCMinutes()}:${user.posts[0].timestamp.getUTCSeconds()}`.padEnd(
47+
dateLengths[index] + 2,
48+
)
49+
: " ".repeat(dateLengths[index] + 2);
50+
});
4351

4452
return `|${userCell}|${cells.join("|")}|`;
4553
});
@@ -92,7 +100,7 @@ export async function get10DaysLeaderboard(start: Date, end: Date) {
92100
});
93101

94102
// display the leaderboard in markdown format
95-
const leaderboardFormatted = `# 10 Days in Public Leaderboard from ${start.toISOString().split("T")[0]} to ${end.toISOString().split("T")[0]}\nGood Luck and have fun!🚀\n\n${generateLeaderboardTable(users)}`;
103+
const leaderboardFormatted = `# 10 Days in Public Leaderboard from ${start.toISOString().split("T")[0]} to ${end.toISOString().split("T")[0]}\n\nGood Luck and have fun!\nTime next to the checkmarks is given in h:m:s local time for that user🚀\n\n${generateLeaderboardTable(users)}`;
96104

97105
return leaderboardFormatted;
98106
}

0 commit comments

Comments
 (0)