Skip to content

Commit

Permalink
fix Discord timestamp calculation
Browse files Browse the repository at this point in the history
Incorrect output:

```
Created commit [update `/example` shortlink](https://acmcsuf.com/code/commit/0333b548246fbddd8c309637f06fd31b14d6f805)!

This shortlink will be expire in <t:1696195785765:R>.
```
  • Loading branch information
EthanThatOneKid committed Oct 1, 2023
1 parent 9597d8e commit 95c6acf
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ export function makeHandler(kv: Deno.Kv) {
if (ttlDuration) {
// Render to Discord timestamp format.
// https://gist.github.com/LeviSnoot/d9147767abeef2f770e9ddcd91eb85aa
const discordTimestamp = `<t:${Date.now() + ttlDuration.raw}:R>`;
const discordTimestamp = toDiscordTimestamp(
(Date.now() + ttlDuration.raw) * 0.001,
);
content +=
`\n\nThis shortlink will be expire in ${discordTimestamp}.`;
`\n\nThis shortlink will be expire ${discordTimestamp}.`;
}

// Send the success message.
Expand Down Expand Up @@ -229,3 +231,7 @@ export function makeShorterOptions(
},
};
}

function toDiscordTimestamp(timestamp: number) {
return `<t:${~~timestamp}:R>`;
}

0 comments on commit 95c6acf

Please sign in to comment.