From 7902b91c38d59cc89da2d3b85c570e927ad5ab28 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Tue, 13 Oct 2026 23:46:04 +1300 Subject: [PATCH] Fix time formatting in different node versions --- src/d2m/converters/message-to-event.js | 2 +- src/d2m/converters/message-to-event.test.js | 4 ++-- src/discord/time.js | 2 +- start.js | 6 ++---- test/test.js | 3 +++ 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/d2m/converters/message-to-event.js b/src/d2m/converters/message-to-event.js index 45d9746..1ed9754 100644 --- a/src/d2m/converters/message-to-event.js +++ b/src/d2m/converters/message-to-event.js @@ -916,7 +916,7 @@ async function messageToEvent(message, guild, options = {}, di) { // Add time if (event.scheduled_end_time) { const formatter = new Intl.DateTimeFormat("en-NZ", {weekday: "long", month: "long", day: "numeric", hour: "numeric", minute: "2-digit", timeZone: "UTC"}) // 9 June at 3:00 pm NZT - var displayTime = formatter.formatRange(new Date(event.scheduled_start_time), new Date(event.scheduled_end_time)) + " (UTC)" + var displayTime = (formatter.formatRange(new Date(event.scheduled_start_time), new Date(event.scheduled_end_time)) + " (UTC)").replaceAll(/\p{Zs}/gv, " ") } else { var displayTime = discordTime.convertDiscordTime(unixSeconds, "F") } diff --git a/src/d2m/converters/message-to-event.test.js b/src/d2m/converters/message-to-event.test.js index a7b1733..44b9fe6 100644 --- a/src/d2m/converters/message-to-event.test.js +++ b/src/d2m/converters/message-to-event.test.js @@ -1589,12 +1589,12 @@ test("message2event: irl invite event renders embed", async t => { { $type: "m.room.message", msgtype: "m.notice", - body: `| Scheduled Event - Sunday, 8 June, 10:00 am – 12:00 pm (UTC)` + body: `| Scheduled Event - Sunday, 8 June, 10:00 am – 12:00 pm (UTC)` + `\n| ## forest exploration` + `\n| ` + `\n| 📍 the dark forest`, format: "org.matrix.custom.html", - formatted_body: `

Scheduled Event - Sunday, 8 June, 10:00 am – 12:00 pm (UTC)

` + formatted_body: `

Scheduled Event - Sunday, 8 June, 10:00 am – 12:00 pm (UTC)

` + `forest exploration` + `

📍 the dark forest

`, "m.mentions": {} diff --git a/src/discord/time.js b/src/discord/time.js index d0f7a04..e9d8f8c 100644 --- a/src/discord/time.js +++ b/src/discord/time.js @@ -44,7 +44,7 @@ function getFormatOptions(style) { function convertDiscordTime(timestamp, style) { const formatter = new Intl.DateTimeFormat("en-NZ", getFormatOptions(style)) const d = new Date(timestamp * 1000) - return formatter.format(d) + " (UTC)" + return (formatter.format(d) + " (UTC)").replaceAll(/\p{Zs}/gv, " ") } module.exports.getFormatOptions = getFormatOptions diff --git a/start.js b/start.js index 728c8af..eb84627 100755 --- a/start.js +++ b/start.js @@ -1,10 +1,8 @@ #!/usr/bin/env node // @ts-check -// Temporal API stabilised in Node.js 26. Previous versions can use `--harmony-temporal`, but that's jank, so have a polyfill. -if (!("Temporal" in globalThis)) { - require("temporal-polyfill-lite/global") -} +// Ensure consistent output from the Intl and Temporal API across Node.js versions +require("temporal-polyfill-lite/global") const fs = require("fs") const sqlite = require("better-sqlite3") diff --git a/test/test.js b/test/test.js index 74d99b1..96326f5 100644 --- a/test/test.js +++ b/test/test.js @@ -1,5 +1,8 @@ // @ts-check +// Ensure consistent output from the Intl and Temporal API across Node.js versions +require("temporal-polyfill-lite/global") + const fs = require("fs") const {join} = require("path") const sqlite = require("better-sqlite3")