This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

chore: move time functions to their own lib

+19 -18
+5 -18
src/features/takes.ts
··· 4 4 import { takes as takesTable } from "../libs/schema"; 5 5 import { eq, and, desc } from "drizzle-orm"; 6 6 import TakesConfig from "../libs/config"; 7 + import { generateSlackDate, prettyPrintTime } from "../libs/time"; 7 8 8 9 type MessageResponse = { 9 10 blocks?: AnyMessageBlock[]; ··· 12 13 }; 13 14 14 15 const takes = async () => { 15 - // Helper function for pretty-printing time 16 - const prettyPrintTime = (ms: number): string => { 17 - const minutes = Math.round(ms / 60000); 18 - if (minutes < 2) { 19 - const seconds = Math.max(0, Math.round(ms / 1000)); 20 - return `${seconds} seconds`; 21 - } 22 - return `${minutes} minutes`; 23 - }; 24 - 25 16 // Helper functions for command actions 26 17 const getActiveTake = async (userId: string) => { 27 18 return db ··· 242 233 const endTime = new Date( 243 234 newTake.startedAt.getTime() + newTake.durationMinutes * 60000, 244 235 ); 245 - const endTimeStr = `<!date^${Math.floor(endTime.getTime() / 1000)}^{time}|${endTime.toLocaleTimeString()}>`; 246 236 247 237 const descriptionText = description 248 238 ? `\n\n*Working on:* ${description}` 249 239 : ""; 250 240 return { 251 - text: `🎬 Takes session started! You have ${prettyPrintTime(newTake.durationMinutes * 60000)} until ${endTimeStr}.${descriptionText}`, 241 + text: `🎬 Takes session started! You have ${prettyPrintTime(newTake.durationMinutes * 60000)} until ${generateSlackDate(endTime)}.${descriptionText}`, 252 242 response_type: "ephemeral", 253 243 blocks: [ 254 244 { ··· 266 256 elements: [ 267 257 { 268 258 type: "mrkdwn", 269 - text: `You have ${prettyPrintTime(newTake.durationMinutes * 60000)} left until ${endTimeStr}.`, 259 + text: `You have ${prettyPrintTime(newTake.durationMinutes * 60000)} left until ${generateSlackDate(endTime)}.`, 270 260 }, 271 261 ], 272 262 }, ··· 468 458 pausedSession.durationMinutes * 60000 + 469 459 (pausedSession.pausedTimeMs || 0), 470 460 ); 471 - const endTimeStr = `<!date^${Math.floor(endTime.getTime() / 1000)}^{time}|${endTime.toLocaleTimeString()}>`; 472 461 473 462 return { 474 463 text: `▶️ Takes session resumed! You have ${prettyPrintTime(pausedSession.durationMinutes * 60000)} remaining in your session.`, ··· 489 478 elements: [ 490 479 { 491 480 type: "mrkdwn", 492 - text: `You have ${prettyPrintTime(pausedSession.durationMinutes * 60000)} remaining until ${endTimeStr}.`, 481 + text: `You have ${prettyPrintTime(pausedSession.durationMinutes * 60000)} remaining until ${generateSlackDate(endTime)}.`, 493 482 }, 494 483 ], 495 484 }, ··· 666 655 endTime.setTime(endTime.getTime() + take.pausedTimeMs); 667 656 } 668 657 669 - const endTimeStr = `<!date^${Math.floor(endTime.getTime() / 1000)}^{time}|${endTime.toLocaleTimeString()}>`; 670 - 671 658 const now = new Date(); 672 659 const remainingMs = endTime.getTime() - now.getTime(); 673 660 ··· 695 682 elements: [ 696 683 { 697 684 type: "mrkdwn", 698 - text: `You have ${prettyPrintTime(remainingMs)} remaining until ${endTimeStr}.`, 685 + text: `You have ${prettyPrintTime(remainingMs)} remaining until ${generateSlackDate(endTime)}.`, 699 686 }, 700 687 ], 701 688 },
+14
src/libs/time.ts
··· 1 + // Helper function for pretty-printing time 2 + export const prettyPrintTime = (ms: number): string => { 3 + const minutes = Math.round(ms / 60000); 4 + if (minutes < 2) { 5 + const seconds = Math.max(0, Math.round(ms / 1000)); 6 + return `${seconds} seconds`; 7 + } 8 + return `${minutes} minutes`; 9 + }; 10 + 11 + // Helper function that generates the slack date format 12 + export const generateSlackDate = (endTime: Date): string => { 13 + return `<!date^${Math.floor(endTime.getTime() / 1000)}^{time}|${endTime.toLocaleTimeString()}>`; 14 + };