Skip to content

Commit

Permalink
Merge pull request #7 from kcoderhtml/Add-timestamp-to-leaderboard
Browse files Browse the repository at this point in the history
Add timestamp to leaderboard
  • Loading branch information
kcoderhtml authored Feb 17, 2024
2 parents aaf4374 + 5ef7927 commit 5807ab0
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions utils/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@ function generateLeaderboardTable(users: user[]): string {
);

const userCell = ` ${user.user}${" ".repeat(maxUsernameLength - user.user.length)} `;
const cells = uniqueTimestamps.map((timestamp, index) =>
postsByDate.has(timestamp)
? " ✓".padEnd(dateLengths[index] + 2)
: " ".repeat(dateLengths[index] + 2),
);
const cells = uniqueTimestamps.map((timestamp, index) => {
const date = postsByDate.has(timestamp)
? user.posts.find(
(p) => p.timestamp.toISOString().split("T")[0] === timestamp,
)
: null;

return date
? ` ✓ ${date.timestamp.getUTCHours()}:${user.posts[0].timestamp.getUTCMinutes()}:${user.posts[0].timestamp.getUTCSeconds()}`.padEnd(
dateLengths[index] + 2,
)
: " ".repeat(dateLengths[index] + 2);
});

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

// display the leaderboard in markdown format
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)}`;
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)}`;

return leaderboardFormatted;
}

0 comments on commit 5807ab0

Please sign in to comment.