Skip to content

Commit

Permalink
fix: change unix timestamp formats to seconds (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
guidojw authored Sep 21, 2023
1 parent 428056d commit d6ae6bb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ export default class TrainingsCommand extends SubCommandCommand<TrainingsCommand
.setTitle(`Training ${training.id}`)
.addFields([
{ name: 'Type', value: training.type?.abbreviation ?? 'Deleted', inline: true },
{ name: 'Date', value: `<t:${date.getTime()}:d>`, inline: true },
{ name: 'Time', value: `<t:${date.getTime()}:t>`, inline: true },
{ name: 'Date', value: `<t:${date.getTime() / 1000}:d>`, inline: true },
{ name: 'Time', value: `<t:${date.getTime() / 1000}:t>`, inline: true },
{ name: 'Host', value: username, inline: true }
])
.setColor(context.primaryColor ?? applicationConfig.defaultColor)
Expand Down
6 changes: 2 additions & 4 deletions src/jobs/announce-trainings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ async function getTrainingsEmbed (groupId: number, trainings: Training[], author

const types = Object.keys(groupedTrainings)
const embed = new EmbedBuilder()
.setFooter({ text: 'Updated at' })
.setTimestamp()

for (let i = 0; i < types.length; i++) {
const type = types[i]
Expand Down Expand Up @@ -110,7 +108,7 @@ function getTrainingMessage (training: Training, authors: GetUsers): string {
const date = new Date(training.date)
const author = authors.find(author => author.id === training.authorId)

let result = `:calendar_spiral: <t:${date.getTime()}:d> at <t:${date.getTime()}:t> hosted by ${author?.name ?? training.authorId}`
let result = `:calendar_spiral: <t:${date.getTime() / 1000}:d> at <t:${date.getTime() / 1000}:t> hosted by ${author?.name ?? training.authorId}`

if (training.notes !== null) {
result += `\n> :notepad_spiral: ${training.notes}`
Expand All @@ -122,7 +120,7 @@ function getNextTrainingMessage (training: Training, authors: GetUsers): string
const date = new Date(training.date)
const author = authors.find(author => author.id === training.authorId)

let result = `${training.type?.abbreviation ?? '(Deleted)'} training on <t:${date.getTime()}:d> at <t:${date.getTime()}:t> hosted by ${author?.name ?? training.authorId}`
let result = `${training.type?.abbreviation ?? '(Deleted)'} training on <t:${date.getTime() / 1000}:d> at <t:${date.getTime() / 1000}:t> hosted by ${author?.name ?? training.authorId}`

if (training.notes !== null) {
result += `\n${training.notes}`
Expand Down
2 changes: 1 addition & 1 deletion src/services/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export function getTrainingRow (training: Training, { users }: { users: GetUsers
const username = users.find(user => user.id === training.authorId)?.name ?? training.authorId
const date = new Date(training.date)

return `${training.id}. **${training.type?.abbreviation ?? '??'}** training on <t:${date.getTime()}:d> at <t:${date.getTime()}:t>, hosted by **${username}**.`
return `${training.id}. **${training.type?.abbreviation ?? '??'}** training on <t:${date.getTime() / 1000}:d> at <t:${date.getTime() / 1000}:t>, hosted by **${username}**.`
}

export function groupTrainingsByType (trainings: Training[]): Record<string, Training[]> {
Expand Down

0 comments on commit d6ae6bb

Please sign in to comment.