Fix time formatting in different node versions
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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: `<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>`
|
||||
+ `<p>📍 the dark forest</p></blockquote>`,
|
||||
"m.mentions": {}
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user