Skip to content

Commit

Permalink
Adjust 'Starts/Ends in ...' for user time zone
Browse files Browse the repository at this point in the history
  • Loading branch information
malted committed Feb 14, 2025
1 parent d2d4c93 commit f6fb28c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ export async function buildSockView(

const latestWakaData = await getLatestWakaData(slackId);

const adjustedNowTimestamp = Date.now() + (tz_offset ?? 0) * 1000;
const adjustedStartTimestamp =
eventStartDate.getTime() + (tz_offset ?? 0) * 1000;
const adjustedEndTimestamp = eventEndDate.getTime() + (tz_offset ?? 0) * 1000;

let rn =
Date.now() < eventStartDate.getTime()
? eventStartDate.getTime() - Date.now()
: eventEndDate.getTime() - Date.now();
adjustedNowTimestamp < adjustedStartTimestamp
? adjustedStartTimestamp - adjustedNowTimestamp
: adjustedEndTimestamp - adjustedNowTimestamp;

let days = Math.floor(rn / (86400 * 1000));
rn -= days * (86400 * 1000);
Expand Down

0 comments on commit f6fb28c

Please sign in to comment.