Skip to content

Commit d2d4c93

Browse files
committed
Display time until event end date when the event is in progress
1 parent 47cd42c commit d2d4c93

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/ui.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
} from "@slack/bolt";
66
import type { ViewsOpenArguments, View } from "@slack/web-api";
77

8-
import { app, eventStartDate } from "./bot";
8+
import { app, eventEndDate, eventStartDate } from "./bot";
99
import { createWakaUser, getLatestWakaData } from "./waka";
1010
import { sql } from "bun";
1111
import { ago, capitaliseFirstLetter } from "./utils";
@@ -49,7 +49,11 @@ export async function buildSockView(
4949

5050
const latestWakaData = await getLatestWakaData(slackId);
5151

52-
let rn = eventStartDate.getTime() - Date.now();
52+
let rn =
53+
Date.now() < eventStartDate.getTime()
54+
? eventStartDate.getTime() - Date.now()
55+
: eventEndDate.getTime() - Date.now();
56+
5357
let days = Math.floor(rn / (86400 * 1000));
5458
rn -= days * (86400 * 1000);
5559
let hours = Math.floor(rn / (60 * 60 * 1000));
@@ -186,7 +190,7 @@ export async function buildSockView(
186190
type: "section",
187191
text: {
188192
type: "mrkdwn",
189-
text: `🧑‍💻 Code for 10 days straight on a *group project*;\n\n🫵 Get Hack Club socks!\n\n🕙 Starts in ${days} days, ${hours} hours, and ${minutes} minutes.`,
193+
text: `🧑‍💻 Code for 10 days straight on a *group project*;\n\n🫵 Get Hack Club socks!\n\n🕙 ${Date.now() < eventStartDate.getTime() ? "Starts" : "Ends"} in ${days} days, ${hours} hours, and ${minutes} minutes.`,
190194
},
191195
accessory: {
192196
type: "image",

0 commit comments

Comments
 (0)