ivnites: use actual inviteDTO for DOMInvite

no intermediary parsing step. Also, moved the date -> duration (3mo6d3h
sorta thing) to the web, there's now a ValidTill field with a unix
timestamp. Used the new Temporal api with a polyfill. Bumped api version
(although it still isn't semver).
This commit is contained in:
Harvey Tindall
2025-12-06 14:01:06 +00:00
parent ab7694b50b
commit 51f604d061
9 changed files with 188 additions and 120 deletions
+31
View File
@@ -1,5 +1,6 @@
declare var window: GlobalWindow;
import dateParser from "any-date-parser";
import { Temporal } from 'temporal-polyfill';
export function toDateString(date: Date): string {
const locale = window.language || (window as any).navigator.userLanguage || window.navigator.language;
@@ -41,6 +42,36 @@ export const parseDateString = (value: string): ParsedDate => {
return out;
}
// DateCountdown sets the given el's textContent to the time till the given date (unixSeconds), updating
// every minute. It returns the timeout, so it can be later removed with clearTimeout if desired.
export function DateCountdown(el: HTMLElement, unixSeconds: number): ReturnType<typeof setTimeout> {
let then = Temporal.Instant.fromEpochMilliseconds(unixSeconds * 1000);
const toString = (): string => {
let out = "";
let now = Temporal.Now.instant();
let nowPlain = Temporal.Now.plainDateTimeISO();
let diff = now.until(then).round({
largestUnit: "years",
smallestUnit: "minutes",
relativeTo: nowPlain
});
// FIXME: I'd really like this to be localized, but don't know of any nice solutions.
const fields = [diff.years, diff.months, diff.days, diff.hours, diff.minutes];
const abbrevs = ["y", "mo", "d", "h", "m"];
for (let i = 0; i < fields.length; i++) {
if (fields[i]) {
out += ""+fields[i] + abbrevs[i] + " ";
}
}
return out.slice(0, -1);
};
const update = () => {
el.textContent = toString();
};
update();
return setTimeout(update, 60000);
}
export const _get = (url: string, data: Object, onreadystatechange: (req: XMLHttpRequest) => void, noConnectionError: boolean = false): void => {
let req = new XMLHttpRequest();
if (window.pages) { url = window.pages.Base + url; }