Repository: louislam/uptime-kuma
File: server/notification-providers/discord.js (JavaScript)

Code before:
                }
                if (notification.discordPrefixMessage) {
                    discorddowndata.content = notification.discordPrefixMessage;
                }
                if (notification.discordSuppressNotifications) {
                    discorddowndata.flags = SUPPRESS_NOTIFICATIONS_FLAG;
                }

                await axios.post(webhookUrl.toString(), discorddowndata, config);
                return okMsg;
            } else if (heartbeatJSON["status"] === UP) {
                // Format timestamp for Discord using Discord's timestamp format
                const backOnlineTimestamp = Math.floor(new Date(heartbeatJSON["time"]).getTime() / 1000);

                // Use downtime information from heartbeatJSON (calculated outside notification provider)
                let downtimeDuration = null;
                let wentOfflineFormatted = null;
                if (heartbeatJSON["lastDownTime"]) {
                    const wentOfflineTimestamp = Math.floor(new Date(heartbeatJSON["lastDownTime"]).getTime() / 1000);
                    wentOfflineFormatted = `<t:${wentOfflineTimestamp}:F>`;

                    // Calculate the actual duration between went offline and back online
                    const durationSeconds = backOnlineTimestamp - wentOfflineTimestamp;

                    // Format duration as human-readable string (e.g., "1h 23m", "45m 30s")
                    const hours = Math.floor(durationSeconds / 3600);
                    const minutes = Math.floor((durationSeconds % 3600) / 60);
                    const seconds = durationSeconds % 60;

                    const durationParts = [];
                    if (hours > 0) {
                        durationParts.push(`${hours}h`);
                    }
                    if (minutes > 0) {
                        durationParts.push(`${minutes}m`);
                    }
                    if (seconds > 0 && hours === 0) {
                        // Only show seconds if less than an hour
                        durationParts.push(`${seconds}s`);
                    }

                    downtimeDuration = durationParts.length > 0 ? durationParts.join(" ") : "0s";
                }

                let discordupdata = {
                    username: discordDisplayName,
                    embeds: [
                        {
                            title: "✅ Your service " + monitorJSON["name"] + " is up! ✅",
                            color: 65280,
                            timestamp: heartbeatJSON["time"],

Review comment (suggestion):
```suggestion
                    // TODO: Update below to Intl.DurationFormat("en", { style: "short" }).format(duration) once we are on a newer node version
                    const hours = Math.floor(durationSeconds / 3600);
```

Code after:
                    discorddowndata.content = notification.discordPrefixMessage;
                }
                if (notification.discordSuppressNotifications) {
                    discorddowndata.flags = SUPPRESS_NOTIFICATIONS_FLAG;
                }

                await axios.post(webhookUrl.toString(), discorddowndata, config);
                return okMsg;
            } else if (heartbeatJSON["status"] === UP) {
                const backOnlineTimestamp = Math.floor(new Date(heartbeatJSON["time"]).getTime() / 1000);
                let downtimeDuration = null;
                let wentOfflineTimestamp = null;
                if (heartbeatJSON["lastDownTime"]) {
                    wentOfflineTimestamp = Math.floor(new Date(heartbeatJSON["lastDownTime"]).getTime() / 1000);
                    downtimeDuration = this.formatDuration(backOnlineTimestamp - wentOfflineTimestamp);
                }

                let discordupdata = {
                    username: discordDisplayName,
                    embeds: [
                        {
                            title: "✅ Your service " + monitorJSON["name"] + " is up! ✅",
                            color: 65280,
                            timestamp: heartbeatJSON["time"],
                            fields: [
                                {
                                    name: "Service Name",
                                    value: monitorJSON["name"],
                                },
                                ...(!notification.disableUrl && addess
                                    ? [
                                          {
                                              name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL",
                                              value: addess,
                                          },
                                      ]
                                    : []),
                                ...(wentOfflineTimestamp
                                    ? [
                                          {
                                              name: "Went Offline",
                                              // F for full date/time
                                              value: `<t:${wentOfflineTimestamp}:F>`,
                                          },
                                      ]
                                    : []),
                                ...(downtimeDuration
                                    ? [
                                          {
                                              name: "Downtime Duration",
                                              value: downtimeDuration,