Skip to content

Commit 66f263d

Browse files
committed
Render Slack alert timestamps in viewer's timezone [TRI-8884]
1 parent e39a351 commit 66f263d

2 files changed

Lines changed: 26 additions & 18 deletions

File tree

apps/webapp/app/v3/services/alerts/deliverAlert.server.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,15 +1182,19 @@ export class DeliverAlertService extends BaseService {
11821182
}
11831183

11841184
#formatTimestamp(date: Date): string {
1185-
return new Intl.DateTimeFormat("en-US", {
1186-
month: "short",
1187-
day: "numeric",
1188-
year: "numeric",
1189-
hour: "numeric",
1190-
minute: "2-digit",
1191-
second: "2-digit",
1192-
hour12: true,
1193-
}).format(date);
1185+
const unix = Math.floor(date.getTime() / 1000);
1186+
const fallback =
1187+
new Intl.DateTimeFormat("en-US", {
1188+
month: "short",
1189+
day: "numeric",
1190+
year: "numeric",
1191+
hour: "numeric",
1192+
minute: "2-digit",
1193+
second: "2-digit",
1194+
hour12: true,
1195+
timeZone: "UTC",
1196+
}).format(date) + " UTC";
1197+
return `<!date^${unix}^{date_short_pretty} {time_secs}|${fallback}>`;
11941198
}
11951199

11961200
#buildWebhookGitObject(git: GitMetaLinks | null) {

apps/webapp/app/v3/services/alerts/deliverErrorGroupAlert.server.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,19 @@ export class DeliverErrorGroupAlertService {
383383
}
384384

385385
#formatTimestamp(date: Date): string {
386-
return new Intl.DateTimeFormat("en-US", {
387-
month: "short",
388-
day: "numeric",
389-
year: "numeric",
390-
hour: "numeric",
391-
minute: "2-digit",
392-
second: "2-digit",
393-
hour12: true,
394-
}).format(date);
386+
const unix = Math.floor(date.getTime() / 1000);
387+
const fallback =
388+
new Intl.DateTimeFormat("en-US", {
389+
month: "short",
390+
day: "numeric",
391+
year: "numeric",
392+
hour: "numeric",
393+
minute: "2-digit",
394+
second: "2-digit",
395+
hour12: true,
396+
timeZone: "UTC",
397+
}).format(date) + " UTC";
398+
return `<!date^${unix}^{date_short_pretty} {time_secs}|${fallback}>`;
395399
}
396400
}
397401

0 commit comments

Comments
 (0)