Fix time formatting in different node versions

This commit is contained in:
Cadence Ember
2026-10-13 23:46:04 +13:00
parent c196bef0ba
commit 7902b91c38
5 changed files with 9 additions and 8 deletions
+1 -1
View File
@@ -916,7 +916,7 @@ async function messageToEvent(message, guild, options = {}, di) {
// Add time // Add time
if (event.scheduled_end_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 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 { } else {
var displayTime = discordTime.convertDiscordTime(unixSeconds, "F") var displayTime = discordTime.convertDiscordTime(unixSeconds, "F")
} }
+2 -2
View File
@@ -1589,12 +1589,12 @@ test("message2event: irl invite event renders embed", async t => {
{ {
$type: "m.room.message", $type: "m.room.message",
msgtype: "m.notice", 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| ## forest exploration`
+ `\n| ` + `\n| `
+ `\n| 📍 the dark forest`, + `\n| 📍 the dark forest`,
format: "org.matrix.custom.html", format: "org.matrix.custom.html",
formatted_body: `<blockquote><p>Scheduled Event - <a href=\"https://bridge.example.org/time/1749376800/F\">Sunday, 8 June, 10:00 am – 12:00 pm (UTC)</a></p>` formatted_body: `<blockquote><p>Scheduled Event - <a href=\"https://bridge.example.org/time/1749376800/F\">Sunday, 8 June, 10:00 am – 12:00 pm (UTC)</a></p>`
+ `<strong>forest exploration</strong>` + `<strong>forest exploration</strong>`
+ `<p>📍 the dark forest</p></blockquote>`, + `<p>📍 the dark forest</p></blockquote>`,
"m.mentions": {} "m.mentions": {}
+1 -1
View File
@@ -44,7 +44,7 @@ function getFormatOptions(style) {
function convertDiscordTime(timestamp, style) { function convertDiscordTime(timestamp, style) {
const formatter = new Intl.DateTimeFormat("en-NZ", getFormatOptions(style)) const formatter = new Intl.DateTimeFormat("en-NZ", getFormatOptions(style))
const d = new Date(timestamp * 1000) const d = new Date(timestamp * 1000)
return formatter.format(d) + " (UTC)" return (formatter.format(d) + " (UTC)").replaceAll(/\p{Zs}/gv, " ")
} }
module.exports.getFormatOptions = getFormatOptions module.exports.getFormatOptions = getFormatOptions
+2 -4
View File
@@ -1,10 +1,8 @@
#!/usr/bin/env node #!/usr/bin/env node
// @ts-check // @ts-check
// Temporal API stabilised in Node.js 26. Previous versions can use `--harmony-temporal`, but that's jank, so have a polyfill. // Ensure consistent output from the Intl and Temporal API across Node.js versions
if (!("Temporal" in globalThis)) { require("temporal-polyfill-lite/global")
require("temporal-polyfill-lite/global")
}
const fs = require("fs") const fs = require("fs")
const sqlite = require("better-sqlite3") const sqlite = require("better-sqlite3")
+3
View File
@@ -1,5 +1,8 @@
// @ts-check // @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 fs = require("fs")
const {join} = require("path") const {join} = require("path")
const sqlite = require("better-sqlite3") const sqlite = require("better-sqlite3")